Alternative generateName behaviour for symbolLookup in DGen #49

Closed
opened 2022-12-15 10:47:52 +00:00 by deavmi · 4 comments
Owner

Currently

If you pass a Container c and Entity e to generateName(Container, Entity) but the entity is not contained by the given container (even if the container provided is contained byu the container that the Entity is contained by), then we get an assertion failure.

Currently we have an example code of:

int k = 22+j;

int banana(int j)
{
    int h = 64;

    k=1;   
}

Now rightfully so, k - the Variable has a Container which is the Module. So therefore the assertion will fail as we pass in a Function as a container.


I don't really want to change the behaviour of our resolver, so maybe it might be a good idea to come up with something else. Like, yeah?

## Currently If you pass a Container `c` and Entity `e` to `generateName(Container, Entity)` but the entity is not contained by the given container (even if the container provided is contained byu the container that the Entity is contained by), then we get an assertion failure. Currently we have an example code of: ```d int k = 22+j; int banana(int j) { int h = 64; k=1; } ``` Now rightfully so, `k` - the `Variable` has a `Container` which is the `Module`. So therefore the assertion will fail as we pass in a `Function` as a container. --- I don't really want to change the behaviour of our resolver, so maybe it might be a good idea to come up with something else. Like, yeah?
Author
Owner

Idea 1

What we could do perhaps, instead of chanigng things around could be to cache symbol lookups, as that is the entire point of this really, for name generation.

We already have (and working):

  1. Entity lookups (needed for correct emit generation)

All we want:

Is generateName basically but to hash it, so perhaps we should cache it in the SymbolMapper, then we avoid things like this. So if it doesn't exist, then do the lookup with the generateName and all, but if it does exist then we should simply get a cached copy returned to us by SymbolMapper.

## Idea 1 What we could do perhaps, instead of chanigng things around could be to cache symbol lookups, as that is the entire point of this really, for name generation. We already have (and working): 1. Entity lookups (needed for correct emit generation) All we want: Is `generateName` basically but to hash it, so perhaps we should cache it in the SymbolMapper, then we avoid things like this. So if it doesn't exist, then do the lookup with the `generateName` and all, but if it **does** exist then we should simply get a cached copy returned to us by `SymbolMapper`.
deavmi changed title from Alternative generateName behaviour to Alternative generateName behaviour for symbolLookup in DGen 2022-12-15 10:52:09 +00:00
deavmi added reference vardec_varass_dependency 2022-12-15 10:53:01 +00:00
deavmi added the
needsfix
resolution
emit
labels 2022-12-15 10:53:18 +00:00
deavmi added this to the Dependency tree, type-checking and codegen project 2022-12-15 10:53:21 +00:00
deavmi self-assigned this 2022-12-15 10:53:24 +00:00
Author
Owner

Idea 2

Better approach, we keep stuff as is in the DGen class to keep it simple and clean but in the VarStdAssignment we set the context there like this:

assert(tc.getResolver().resolveBest(c, vAsStdAl.getVariableName()));
gprintln("YEAST ENJOYER");

Variable variable = cast(Variable)tc.getResolver().resolveBest(c, vAsStdAl.getVariableName());
assert(variable);

vAsStdAl.setContext(variable.getContext());

Instead of this:

vAsStdAl.setContext(context);

Effectively using the context of the variable the standalone assignment refers to which should always be correct.

## Idea 2 Better approach, we keep stuff as is in the `DGen` class to keep it simple and clean **but** in the `VarStdAssignment` we set the context there like this: ```d assert(tc.getResolver().resolveBest(c, vAsStdAl.getVariableName())); gprintln("YEAST ENJOYER"); Variable variable = cast(Variable)tc.getResolver().resolveBest(c, vAsStdAl.getVariableName()); assert(variable); vAsStdAl.setContext(variable.getContext()); ``` Instead of this: ```d vAsStdAl.setContext(context); ``` --- Effectively using the context of the variable the standalone assignment refers to which should always be correct.
Author
Owner

Going with idea 2

Going with idea 2
Author
Owner

Fixed with commit 2a12c310a66e42783a524cd58f040454c1c36197 on branch vardec_varass_dependency

Fixed with commit `2a12c310a66e42783a524cd58f040454c1c36197` on branch `vardec_varass_dependency`
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: tlang/tlang#49
No description provided.