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

Optimizer gets confused if e.g., unit names contain double underscores #1504

Closed
bbannier opened this issue Aug 28, 2023 · 1 comment · Fixed by #1505
Closed

Optimizer gets confused if e.g., unit names contain double underscores #1504

bbannier opened this issue Aug 28, 2023 · 1 comment · Fixed by #1505
Assignees
Labels
Bug Something isn't working Compiler

Comments

@bbannier
Copy link
Member

In order to track feature requirements the optimizer uses variables with names derived from the unit name, e.g., for a unit foo::Bar we generate feature variables __feat%foo__Bar. We here normalize : as _. Since _ is valid in user-specified identifiers this can clash with user code similar to #1499, e.g.,

# foo.spicy
module foo;

public type X__x = unit {
    on %init { print self.offset(); }
};
$ echo | spicy-driver foo.spicy
[error] terminating with uncaught exception of type hilti::rt::UnsetOptional: unset optional value (foo.spicy:5:16)
@bbannier bbannier added Bug Something isn't working Compiler labels Aug 28, 2023
@bbannier bbannier self-assigned this Aug 28, 2023
bbannier added a commit that referenced this issue Aug 28, 2023
When setting up feature tracking variables for the optimizer we
previously would normalize `:` as `_`, e.g., `mod::Unit` would lead to
feature variables `__feat%mod__Unit%...`. In various places in the
optimizer we would then use that knowledge to extract module and unit
ID. Since user-specified identifiers can contain literal `_` or `__`
this could confuse the optimizer.

With this patch we now normalize `:` as `@` which is not
user-accessible. We add a new codegen normalization so `@` becomes
`0x40`. This gives a more reliable encoding.

Closes #1504.
@bbannier
Copy link
Member Author

bbannier commented Aug 28, 2023

In all versions before this fix, users should avoid using double underscores in type names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant