rust/src/libsyntax
Alex Crichton d889957dab rustc: Add a #[wasm_import_module] attribute
This commit adds a new attribute to the Rust compiler specific to the wasm
target (and no other targets). The `#[wasm_import_module]` attribute is used to
specify the module that a name is imported from, and is used like so:

    #[wasm_import_module = "./foo.js"]
    extern {
        fn some_js_function();
    }

Here the import of the symbol `some_js_function` is tagged with the `./foo.js`
module in the wasm output file. Wasm-the-format includes two fields on all
imports, a module and a field. The field is the symbol name (`some_js_function`
above) and the module has historically unconditionally been `"env"`. I'm not
sure if this `"env"` convention has asm.js or LLVM roots, but regardless we'd
like the ability to configure it!

The proposed ES module integration with wasm (aka a wasm module is "just another
ES module") requires that the import module of wasm imports is interpreted as an
ES module import, meaning that you'll need to encode paths, NPM packages, etc.
As a result, we'll need this to be something other than `"env"`!

Unfortunately neither our version of LLVM nor LLD supports custom import modules
(aka anything not `"env"`). My hope is that by the time LLVM 7 is released both
will have support, but in the meantime this commit adds some primitive
encoding/decoding of wasm files to the compiler. This way rustc postprocesses
the wasm module that LLVM emits to ensure it's got all the imports we'd like to
have in it.

Eventually I'd ideally like to unconditionally require this attribute to be
placed on all `extern { ... }` blocks. For now though it seemed prudent to add
it as an unstable attribute, so for now it's not required (as that'd force usage
of a feature gate). Hopefully it doesn't take too long to "stabilize" this!

cc rust-lang-nursery/rust-wasm#29
2018-03-22 13:16:38 -07:00
..
diagnostics Auto merge of #48917 - petrochenkov:import, r=oli-obk 2018-03-18 01:50:52 +00:00
ext Auto merge of #48917 - petrochenkov:import, r=oli-obk 2018-03-18 01:50:52 +00:00
parse Rollup merge of #49117 - nivkner:fixme_fixup3, r=estebank 2018-03-22 22:43:37 +08:00
print Auto merge of #48917 - petrochenkov:import, r=oli-obk 2018-03-18 01:50:52 +00:00
util Replace Rc with Lrc for shared data 2018-03-02 10:48:52 +01:00
abi.rs add thiscall calling convention support 2017-05-24 16:40:03 -04:00
ast.rs Add some docs + Fix rebase 2018-03-17 22:29:15 +03:00
attr.rs Remove syntax and syntax_pos thread locals 2018-03-14 11:56:01 +01:00
build.rs rustc: Add some build scripts for librustc crates 2017-07-22 22:04:13 -07:00
Cargo.toml Remove syntax and syntax_pos thread locals 2018-03-14 11:56:01 +01:00
codemap.rs CodeMap functions refactored. 2018-03-18 20:46:29 -03:00
config.rs Make it possible to ungate features by epoch 2018-03-08 17:10:05 -08:00
diagnostic_list.rs Stabilize inclusive_range_syntax language feature. 2018-03-15 16:58:02 +08:00
entry.rs Cleanup InternedString. 2016-11-21 09:00:56 +00:00
epoch.rs Note the future epoch for epoch lints 2018-03-08 17:10:06 -08:00
feature_gate.rs rustc: Add a #[wasm_import_module] attribute 2018-03-22 13:16:38 -07:00
fold.rs Rename Span::empty to Span::shrink_to_lo, add Span::shrink_to_hi 2018-03-17 22:12:21 +03:00
json.rs Require the code mapper to be thread-safe 2018-03-15 00:43:03 +01:00
lib.rs Remove syntax and syntax_pos thread locals 2018-03-14 11:56:01 +01:00
ptr.rs syntax: Rename P::unwrap into P::into_inner 2017-12-17 02:21:29 +03:00
README.md Replace many of the last references to readmes 2018-03-16 12:43:22 -05:00
show_span.rs use field init shorthand EVERYWHERE 2017-08-15 15:29:17 -07:00
std_inject.rs Rename Span::empty to Span::shrink_to_lo, add Span::shrink_to_hi 2018-03-17 22:12:21 +03:00
str.rs syntax: Copy unstable str::char_at into libsyntax 2015-04-21 10:23:53 -07:00
test.rs Rollup merge of #49117 - nivkner:fixme_fixup3, r=estebank 2018-03-22 22:43:37 +08:00
test_snippet.rs Remove syntax and syntax_pos thread locals 2018-03-14 11:56:01 +01:00
tokenstream.rs Remove syntax and syntax_pos thread locals 2018-03-14 11:56:01 +01:00
visit.rs AST: Make renames in imports closer to the source 2018-03-17 22:12:21 +03:00

The syntax crate contains those things concerned purely with syntax that is, the AST ("abstract syntax tree"), parser, pretty-printer, lexer, macro expander, and utilities for traversing ASTs.

For more information about how these things work in rustc, see the rustc guide: