mirror of
https://github.com/enso-org/enso.git
synced 2024-11-26 17:06:48 +03:00
bc66078251
Implement generation of Java AST types from the Rust AST type definitions, with support for deserializing in Java syntax trees created in Rust. ### New Libraries #### `enso-reflect` Implements a `#[derive(Reflect)]` macro to enable runtime analysis of datatypes. Macro interface includes helper attributes; **the Rust types and the `reflect` attributes applied to them fully determine the Java types** ultimately produced (by `enso-metamodel`). This is the most important API, as it is used in the subject crates (`enso-parser`, and dependencies with types used in the AST). [Module docs](https://github.com/enso-org/enso/blob/wip/kw/parser/ast-transpiler/lib/rust/reflect/macros/src/lib.rs). #### `enso-metamodel` Provides data models for data models in Rust/Java/Meta (a highly-abstracted language-independent model--I have referred to it before as the "generic representation", but that was an overloaded term). The high-level interface consists of operations on data models, and between them. For example, the only operations needed by [the binary that drives datatype transpilation](https://github.com/enso-org/enso/blob/wip/kw/parser/ast-transpiler/lib/rust/parser/generate-java/src/main.rs) are: `rust::to_meta`, `java::from_meta`, `java::transform::optional_to_null`, `java::to_syntax`. The low-level interface consists of direct usage of the datatypes; this is used by [the module that implements some serialization overrides](https://github.com/enso-org/enso/blob/wip/kw/parser/ast-transpiler/lib/rust/parser/generate-java/src/serialization.rs) (so that the Java interface to `Code` references can produce `String`s on demand based on serialized offset/length pairs). The serialization override mechanism is based on customizing, not replacing, the generated deserialization methods, so as to be as robust as possible to changes in the Rust source or in the transpilation process. ### Important Notes - Rust/Java serialization is exhaustively tested for structural compatibility. A function [`metamodel::meta::serialization::testcases`](https://github.com/enso-org/enso/blob/wip/kw/parser/ast-transpiler/lib/rust/metamodel/src/meta/serialization.rs) uses `reflect`-derived data to generate serialized representations of ASTs to use as test cases. Its should-accept cases cover every type a tree can contain; it also produces a representative set of should-reject cases. A Rust `#[test]` confirms that these cases are accepted/rejected as expected, and generated Java tests (see Binaries below) check the generated Java deserialization code against the same test cases. - Deserializing `Code` is untested. The mechanism is in place (in Rust, we serialize only the offset/length of the `Cow`; in Java, during deserialization we obtain a context object holding a buffer for all string data; the accessor generated in Java uses the buffer and the offset/length to return `String`s), but it will be easier to test once we have implemented actually parsing something and instantiating the `Cow`s with source code. - `#[tagged_enum]` [now supports](https://github.com/enso-org/enso/blob/wip/kw/parser/ast-transpiler/lib/rust/shapely/macros/src/tagged_enum.rs#L36-L51) control over what is done with container-level attributes; they can be applied to the container and variants (default), only to the container, or only to variants. - Generation of `sealed` classes is supported, but currently disabled by `TARGET_VERSION` in `metamodel::java::syntax` so that tests don't require Java 15 to run. (The same logic is run either way; there is a shallow difference in output.) ### Binaries The `enso-parser-generate-java` crate defines several binaries: - `enso-parser-generate-java`: Performs the transpilation; after integration, this will be invoked by the build script. - `java-tests`: Generates the Java code that tests format deserialization; after integration this command will be invoked by the build script, and its Java output compiled and run during testing. - `graph-rust`/`graph-meta`/`graph-java`: Produce GraphViz representations of data models in different typesystems; these are for developing and understanding model transformations. Until integration, a **script regenerates the Java and runs the format tests: `./tools/parser_generate_java.sh`**. The generated code can be browsed in `target/generated_java`.
67 lines
1.7 KiB
TOML
67 lines
1.7 KiB
TOML
[workspace]
|
|
# Listing only the "root" crates of each app/library. All path dependencies are included in the workspace automatically.
|
|
# If you want to add sub crate (like `app/gui/config` or `lib/rust/ensogl/example`), just add it as a path dependency
|
|
# where plausible.
|
|
members = [
|
|
"app/gui",
|
|
"app/gui/enso-profiler-enso-data",
|
|
"build",
|
|
"build/enso-formatter",
|
|
"build/rust-scripts",
|
|
"lib/rust/*",
|
|
"lib/rust/parser/src/syntax/tree/visitor",
|
|
"lib/rust/parser/src/syntax/tree/builder",
|
|
"lib/rust/parser/generate-java",
|
|
"lib/rust/profiler/data",
|
|
"integration-test"
|
|
]
|
|
# The default memebers are those we want to check and test by default.
|
|
default-members = ["app/gui", "lib/rust/*"]
|
|
|
|
# We are using a version with extended functionality. The changes have been PR'd upstream:
|
|
# https://github.com/rustwasm/console_error_panic_hook/pull/24
|
|
# Remove this patch when the issue is resolved.
|
|
[patch.crates-io]
|
|
console_error_panic_hook = { git = 'https://github.com/enso-org/console_error_panic_hook' }
|
|
|
|
[profile.dev]
|
|
opt-level = 0
|
|
lto = false
|
|
debug = 0
|
|
debug-assertions = true
|
|
|
|
[profile.release]
|
|
opt-level = 3
|
|
lto = "thin"
|
|
codegen-units = 16
|
|
incremental = true
|
|
debug = false
|
|
debug-assertions = false
|
|
|
|
[profile.bench]
|
|
opt-level = 3
|
|
lto = true
|
|
debug = false
|
|
debug-assertions = false
|
|
|
|
[profile.test]
|
|
opt-level = 0
|
|
lto = false
|
|
debug = true
|
|
debug-assertions = true
|
|
|
|
[profile.integration-test]
|
|
inherits = "test"
|
|
opt-level = 2
|
|
|
|
[profile.buildscript]
|
|
inherits = "release"
|
|
opt-level = 2
|
|
lto = false
|
|
debug = false
|
|
debug-assertions = true
|
|
#[patch."https://github.com/enso-org/ci-build"]
|
|
#enso-build = { path = '../ci-build/build' }
|
|
#enso-build-cli = { path = '../ci-build/cli' }
|
|
#ide-ci = { path = '../ci-build/ci_utils' }
|