Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

Newtype optimisation broken in the REPL #196

Closed
plt-amy opened this issue Oct 15, 2019 · 3 comments · Fixed by #210
Closed

Newtype optimisation broken in the REPL #196

plt-amy opened this issue Oct 15, 2019 · 3 comments · Fixed by #210
Assignees
Labels
bug X-soundness Soundness bugs.
Milestone

Comments

@plt-amy
Copy link
Member

plt-amy commented Oct 15, 2019

Load this file then try matching on x—You can't. The pattern won't be lowered to a cast and we'll try to index a string.

type foo = Foo of string

let x = Foo "foo"
@plt-amy plt-amy added bug X-soundness Soundness bugs. labels Oct 15, 2019
@plt-amy plt-amy added this to the 1.0.0.0 milestone Oct 15, 2019
@plt-amy
Copy link
Member Author

plt-amy commented Oct 15, 2019

bbb303c disables newtype opt in the repl but we still need to address it.

@plt-amy
Copy link
Member Author

plt-amy commented Oct 15, 2019

Of course a possible solution is just stating that newtype optimisation isn't guaranteed to run.

@SquidDev
Copy link
Member

SquidDev commented Oct 15, 2019

Yeah, this is something I've been thinking about for a while - if we ever start running the optimiser before linking modules together (which we should), then we need to think about this.

I think the only correct thing to do here is to implement the optimisation as part of lowering. Unlike other optimisations, it actually changes the signature (and sometimes semantics) of the module, so I think this is our only option. We'd then effectively store a "type representation" flag within the LowerState, and use that to guide lowering of other modules.

This is obviously going to make pattern lowering even more ugly, but I think it's the best solution.

@SquidDev SquidDev self-assigned this Oct 15, 2019
SquidDev added a commit that referenced this issue Oct 28, 2019
 - Introduce the concept of "type representations". These are a concrete
   part of the (core) module signature, rather than provided by an
   optimisation.

 - Lower is now guided by these type representations. We will emit
   method calls instead of constructor invocations for type wrappers,
   and the pattern compiler will also generate the appropriate code.

Closes #196
plt-amy pushed a commit that referenced this issue Oct 28, 2019
- Introduce the concept of "type representations". These are a concrete
   part of the (core) module signature, rather than provided by an
   optimisation.

 - Lower is now guided by these type representations. We will emit
   method calls instead of constructor invocations for type wrappers,
   and the pattern compiler will also generate the appropriate code.

Closes #196
plt-amy pushed a commit that referenced this issue Jan 12, 2020
- Introduce the concept of "type representations". These are a concrete
   part of the (core) module signature, rather than provided by an
   optimisation.

 - Lower is now guided by these type representations. We will emit
   method calls instead of constructor invocations for type wrappers,
   and the pattern compiler will also generate the appropriate code.

Closes #196
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug X-soundness Soundness bugs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants