Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to represent variable templates? #153

Open
Xazax-hun opened this issue May 19, 2021 · 6 comments
Open

How to represent variable templates? #153

Xazax-hun opened this issue May 19, 2021 · 6 comments

Comments

@Xazax-hun
Copy link
Contributor

I wanted to create a mapping from template parameters to Var with a Forall type, but I encountered some difficulties.

  • What should be the target type for Forall?
  • What should be the type for the Var node under the mapping?
  • How should that Var node be created? Region::declare_var() will add the var to the scope in the Region. As a result, I will end up having the same Var node twice in the tree. Once as the child of the Mapping, and once directly in the scope of the Region.
@GabrielDosReis
Copy link
Owner

GabrielDosReis commented May 26, 2021

What should be the target type for Forall?

The target() of the Forall type node should be the declared type of the current instantiation of the variable template declaration. That is, for example, in

template<typename T>
constexpr T* nil = nullptr;

the target() node should designate the representation of the type const T*.

What should be the type for the Var node under the mapping?

In the example above, the type node should be the representation of const T* -- that is the type of the current instantiation.

How should that Var node be created? Region::declare_var() will add the var to the scope in the Region. As a result, I will end up having the same Var node twice in the tree. Once as the child of the Mapping, and once directly in the scope of the Region.

Well, there are two declarations in that "single template declaration": (a) the declaration of the template (represented by a Named_map node, with name nil), and the declaration of the current instantiation (represented by a Var node, with name nil<T>). They should be distinct names and of distinct node types. You shouldn't invoke declare_var() on both.

@Xazax-hun
Copy link
Contributor Author

You shouldn't invoke declare_var() on both.

I did not invoke it on both, but this is not the problem. I would expect to have IPR like:

\- Named_map
  \- Var

So only Named_map is part of the parent Region, but Var is not. But the only way to create a Var node is to invoke declare_var on a Region, which will also add the Var to the region. Ending up in a tree like:

|- Named_map
|  \- Var
\- Var

So I only called declare_var once, but as a result, I have the same Var at two places in the tree.

@GabrielDosReis
Copy link
Owner

So I only called declare_var once, but as a result, I have the same Var at two places in the tree.

On which node?

@Xazax-hun
Copy link
Contributor Author

Xazax-hun commented May 26, 2021

There is a Region , where I want to put the variable template.
I do the following:

  1. Create the name and the forall type for the template
  2. Create the template via Region::declare_primary_template
  3. Now I need to create a Var that I can use as the body of the template, and the only way to get it (as far as I understand), is to do Region::declare_var. But if I invoke Region::declare_var, I will have the Var node twice in the tree. Once as a member of the Region, and once, as the body of the template I created via Region::declare_primary_template

@GabrielDosReis
Copy link
Owner

See also conversation in #122

@GabrielDosReis
Copy link
Owner

The proposed resolution for this (and many other declarative templates): use a Where node (whose parent region is the template parameter scope region of the Template) with

  • main: the current instantiation, e.g. Var<T>. That current instantiation can be constructed by calling declare_var() on the region member related to the attendant().
  • attendant: the scope returned by the region member of ipr::impl::Where.

Note: the Where node becomes the result() of the ipr::Template (formerly ipr::Named_map).

Also see #191 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants