Add a builtin prelude for List/Array/Map (no import required) #72
Labels
No labels
bug
design
epic
risk
user-story
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
jacksonopp/twill#72
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow-up to #69 — split out during that issue's implementation.
#69 (and its follow-up #71 for
Array'sComptimesize) built the mechanism for comptime-evaluating a generic type-function call (List(Int)etc.) into a realTy, viafn_decllooking up the callee's declaration andevaluate_generic_callsubstituting args into its body. Butfn_declonly ever searches theSourceFileit's given — in every #69/#71 test,List's ownfn List(T: type) -> type { struct { items: *T, len: Int } }is declared inline in the same source being checked. There is currently no way for a real program to useList(Int), or the[1, 2, 3]/[3]Int[...]/["a": 1]literal sugar (persyntax-notes.md) that desugars to it, without redeclaringList/Array/Mapitself in every file.This is not a standard-library/import feature. Per
syntax-notes.md,List/Array/Mapare used completely unqualified everywhere — the container-literal sugar desugars straight toList(Int)/Array(Int, 3)/Map(String, Int)with noimportin sight, andimport's own path-to-filesystem resolution is explicitly unbuilt (deferred persyntax-status.md). So this issue is scoped to a builtin/prelude set — analogous to howVecin Rust doesn't need importing (it's ordinary Rust source, just glob-imported by the prelude), not analogous toInt/Bool/Float/String/Unit, which really are Rust-hardcoded compiler builtins (primitive_tyinty.rs— a bare match, no backing declaration at all).List/Array/Mapshould stay real, parseable, comptime-evaluated Twill source, not join that hardcoded list — just be guaranteed findable without a user-written declaration.Proposed shape:
.twsource file(s) (e.g.crates/twill-check/prelude/{list,array,map}.twor one combined file) containing the actual definitions fromsyntax-notes.md.include_str!them into a dedicated, fixed preludeSourceFilecreated once (not resolved through any runtime/filesystem import mechanism — sidestepsimport's unbuilt path resolution entirely).fn_decl(or a wrapper around it) gains a two-tier lookup: try the checked file's ownScope::sourcefirst, then fall back to the preludeSourceFile.Explicitly out of scope: a general importable standard library,
importpath-to-filesystem resolution, and anything beyond this fixed, always-in-scope container set.