Repository navigation
feat(analyser): make Any a top type that takes a cast to get a value out 📦 #353
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -228,17 +228,18 @@ impl Analyser { | |
| } | ||
|
|
||
| /// The instance of `function` for these types of its key: the function | ||
| /// itself when they're all `Any`, as its own body picks its calls as the | ||
| /// program runs, or when it was declared by an earlier batch, which | ||
| /// compiled it already. | ||
| /// itself when it was declared by an earlier batch, which compiled it | ||
| /// already. | ||
| fn instance_for( | ||
| &mut self, | ||
| function: SymbolId, | ||
| key: Vec<StaticType>, | ||
| new: &mut Vec<(SymbolId, SymbolId, Vec<StaticType>)>, | ||
| ) -> SymbolId { | ||
| let is_own = key.iter().all(|typ| *typ == StaticType::Any); | ||
| if is_own || !self.declared_in_batch.contains(&function) { | ||
| // A call with `Any` arguments gets an instance too: its calls take | ||
| // only the overloads that take `Any`, while the function's own body | ||
| // leaves its picks to the program, for its value. | ||
| if !self.declared_in_batch.contains(&function) { | ||
| return function; | ||
|
Comment on lines
+242
to
243
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a generic function was declared on an earlier REPL line, this branch still bypasses specialization. For example, evaluate Useful? React with 👍 / 👎.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Real, but it needs later REPL lines to compile instances of earlier lines' functions; tracked in #354. |
||
| } | ||
| if let Some(&instance) = self.instances.get(&(function, key.clone())) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a generic wrapper receives an actual
Any, its copied constraints now select only the overload acceptingAny, butinstance_forstill reuses the unspecialized body whenever every key type isAny. That body retains the permissive runtime dispatch recorded here. For example, withfn pick(x: Int) => 1; fn pick(x: Any) => "fallback"; fn wrap(x) => pick(x); let a: Any = 1;,wrap(a)is inferred asStringbut executes theIntoverload and returns1. Besides violating the new overload rule, this lets subsequent statically typed operations receive the wrong runtime type. ActualAnycalls need their own specialized picks rather than reusing the generic runtime-dispatched body.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 58993f3: a call with
Anyarguments now gets its own instance (test 017_dynamic_any/027).