Repository navigation
Conversation
'static e' has type StaticPtr t when the closed expression e has type t. The desugarer moves e to a top level definition of its own, whose name identifies the pointer in every run of the program, and the linker puts all of them in a table, so a name can be looked up again (unsafeLookupStaticPtr). 'static' is only a keyword when the program has no 'static' of its own in scope. There is no Typeable constraint. See augustss#498. Co-Authored-By: Claude <noreply@anthropic.com>
static keyword and Mhs.StaticPtr
generated/mhs.c and generated/base.pkg regenerated (mhs.c at a fixpoint). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
generated/mhs.c and generated/base.pkg regenerated (mhs.c at a fixpoint). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
static length, id, Just at more than one type, static inside a polymorphic function, and a polymorphic pointer looked up by name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds static pointers (augustss#498), so that miso's LynxJS backend (
-fnative) can be built with MicroHs.How it works
staticis an ordinary identifier. When the program has nostaticof its own in scope, the type checker usesMhs.StaticPtr._static :: a -> StaticPtr a(throughMhs.Builtin).Desugar.liftStatic). Everystatic ein a definitionfbecomes a top level definitionf$staticN = _mkStaticPtr "M.f$staticN" e. The name is the key: it is the same in every run of the same program.euses a variable bound in the enclosing definition (this includes a dictionary from the context of the enclosing function), or ifstaticis not applied to an argument.Main.addStaticPtrs). When linking,Mhs.StaticPtr._staticPtrTableis replaced by the list of all the$staticdefinitions, the same wayMicroHs.Embed.packagesis filled in.Compared to GHC
Typeableconstraint.e, except that it cannot need a dictionary from the enclosing function. Polymorphic pointers work (seetests/StaticPtrPoly.hs);bad :: Show a => a -> StaticPtr (a -> String); bad _ = static showis rejected as not closed.let/where) binding can only be used inewhen the desugarer inlines it (used once, or a variable or literal). GHC accepts all closed local bindings.Stringname (staticPtrName), not aFingerprint: base has noGHC.Fingerprint(it is in ghc-compat, which is not included by default). AGHC.StaticPtrwithStaticKey = Fingerprintcan be a small module on top of this one that hashes the name (base hasSystem.IO.MD5). Its keys would still not match GHC's, which come from the unit id, the module and a counter; static keys only mean something within one build of one program anyway.Tested
tests/StaticPtr.hs, added toall.tests;all.testsanderr.testspass with a compiler built from this branch.tests/StaticPtrPoly.hs, also inall.tests: polymorphic static pointers (static length :: StaticPtr ([a] -> Int),static id,static Just) used at several types,staticinside a polymorphic function, and a polymorphic pointer looked up by name.nativeflag installs with mcabal, andsample-app-nativecompiles and links with emcc (-sWASM=0 -sENVIRONMENT=shell).staticKey/unsafeLookupStaticPtrround trip through aGHC.StaticPtrshim that hashes the name, as JavaScript only, under node. (miso's committedffi/mhs/GHC/StaticPtr.hsis still the stub, whereunsafeLookupStaticPtralways returnsNothing.)Not tested: a program running in a Lynx host.
Not done
lynxtarget inmhs.conf.in.