motoko icon indicating copy to clipboard operation
motoko copied to clipboard

feat: support `import` values from `file:` URI scheme

Open ggreif opened this issue 9 months ago • 1 comments

I am suggesting importing amorphous files using the file: URI scheme:

import (blobby : Blob) = "file:Bla.wasm";
import (texty : Text) = "file:Bla.md";
import (principally : Principal) = "file:Bla.txt";

Leaving the type away would default to Blob.

To develop this idea further, import (friends : [{ name : Text; birthday : Text; ...}]) = "file:friends.csv" would be in reach. But I am sceptical of the utility (for other than test data generation).

Eventually resolves #4934.


This is super early, I am butchering basically everything, such as

  • type checker (T.Pre at bad phases)
  • compilation units (there should be a ValueU)
  • it should be file://
  • use check_text

ggreif avatar Mar 05 '25 20:03 ggreif

I think it might be easier to have differnt uris

impor bloby = "blob:Bla.wasm"; import texty = "text:Bla.md"; import principally = "principal:Bla.txt"; import envvar= "env:USER"; import foreignclass= "class:foo.wasm";

crusso avatar Mar 13 '25 17:03 crusso

hey @ggreif i see you made good progress here, any ETA 👀

letmejustputthishere avatar Apr 29 '25 10:04 letmejustputthishere

I picked it up again, and swapping back in my brain how all the parts are interacting. It is a bit tricky how to type check it when the type is ultimately guided by the pattern, but I have an idea how to make it smooth (also for the users) and expandable in the future.

ggreif avatar Apr 29 '25 12:04 ggreif

but I have an idea how to make it smooth (also for the users) and expandable in the future.

awesome, looking forward to it 🦾

letmejustputthishere avatar Apr 30 '25 12:04 letmejustputthishere

Comparing from f781c1f50b6f7653cbc6c12ca98ed54627278e68 to f412c5a43fc2cc08c8e526cacfbaa21bf1b84247: The produced WebAssembly code seems to be completely unchanged. In terms of gas, no changes are observed in 5 tests. In terms of size, no changes are observed in 5 tests.

github-actions[bot] avatar May 09 '25 08:05 github-actions[bot]

I'd prefer to have the content type be part of the import URI, similar to what Claudio proposed. That wouldn't require special casing in the type checker and allow tools that use the --print-deps flag to check the imported files according to the specified encoding, without having to perform type checking.

christoph-dfinity avatar May 28 '25 15:05 christoph-dfinity

I think the file protocol is painting us into a corner since it's not longer obvious what the type is and we might later want to import Text values.

Why don't we just use a mo.* prefix to scope the mo specific protocols:

impor bloby = "mo.blob:/Bla.wasm"; import texty = "mo.text:/Bla.md"; (* validate as utf8 *)

Later:

import csv = "mo.csv:/foo.csv"; (* import structured constant or what ever *) import principally = "mo.principal:/Bla.txt"; import envvar= "mo.env:/USER"; import foreignclass= "mo.class:/foo.wasm"; (uses .did type to import foreign actor class *)

cf: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml

Or maybe file.* instead of mo.*

crusso avatar Jul 31 '25 09:07 crusso

I did a doc/make preview and noticed some missing doc in the manual (we have two sections on imports). I added the doc. Will approve now.

crusso avatar Sep 12 '25 07:09 crusso

wow very excited to use this! great work 🎉

letmejustputthishere avatar Sep 12 '25 14:09 letmejustputthishere