From 5277561e77c4259c312b1ac51672ee485d211e97 Mon Sep 17 00:00:00 2001 From: Alexey Orlenko Date: Wed, 13 Aug 2025 00:42:56 +0200 Subject: [PATCH] no_std query compiler --- Cargo.lock | 106 +++++++++++++----- Cargo.toml | 104 +++++++++++------ libs/crosstarget-utils/Cargo.toml | 2 +- libs/crosstarget-utils/src/common/datetime.rs | 7 ++ libs/lazy-race/Cargo.toml | 10 ++ libs/lazy-race/src/lib.rs | 57 ++++++++++ libs/prisma-value/src/arithmetic.rs | 2 +- libs/prisma-value/src/error.rs | 7 +- libs/prisma-value/src/lib.rs | 18 ++- libs/prisma-value/src/raw_json.rs | 2 + libs/prisma-value/src/tagged.rs | 6 +- libs/query-template/src/fragment.rs | 2 +- libs/query-template/src/lib.rs | 4 + libs/query-template/src/placeholder.rs | 4 +- libs/query-template/src/template.rs | 5 +- libs/shared-wasm/src/lib.rs | 2 + libs/telemetry/Cargo.toml | 2 +- libs/telemetry/src/collector.rs | 2 +- libs/telemetry/src/exporter.rs | 2 +- psl/diagnostics/src/collection.rs | 12 +- psl/diagnostics/src/error.rs | 8 +- psl/diagnostics/src/lib.rs | 5 + .../src/native_type_error_factory.rs | 2 + psl/diagnostics/src/pretty_print.rs | 7 +- psl/diagnostics/src/warning.rs | 8 +- psl/parser-database/Cargo.toml | 2 +- psl/parser-database/src/attributes.rs | 7 +- psl/parser-database/src/attributes/default.rs | 2 + psl/parser-database/src/attributes/id.rs | 2 +- .../src/attributes/native_types.rs | 5 + .../src/attributes/shard_key.rs | 2 +- psl/parser-database/src/coerce_expression.rs | 2 + psl/parser-database/src/context.rs | 7 +- psl/parser-database/src/files.rs | 7 +- psl/parser-database/src/interner.rs | 2 + psl/parser-database/src/lib.rs | 13 ++- psl/parser-database/src/names.rs | 4 +- psl/parser-database/src/relations.rs | 10 +- psl/parser-database/src/types.rs | 12 +- psl/parser-database/src/types/index_fields.rs | 2 + .../src/walkers/composite_type.rs | 1 + psl/parser-database/src/walkers/field.rs | 1 + psl/parser-database/src/walkers/index.rs | 1 + psl/parser-database/src/walkers/model.rs | 2 + .../walkers/relation/implicit_many_to_many.rs | 4 +- .../src/walkers/relation/inline.rs | 2 + .../src/walkers/relation_field.rs | 10 +- .../src/walkers/scalar_field.rs | 2 +- psl/psl-core/Cargo.toml | 5 +- .../cockroach_datamodel_connector.rs | 7 +- .../src/builtin_connectors/completions.rs | 2 + .../src/builtin_connectors/mongodb.rs | 3 +- .../mongodb/mongodb_types.rs | 5 +- .../mssql_datamodel_connector.rs | 6 + .../mssql_datamodel_connector/native_types.rs | 6 +- .../mysql_datamodel_connector.rs | 2 + .../native_type_definition.rs | 6 +- .../postgres_datamodel_connector.rs | 9 +- .../datasource.rs | 6 +- .../sqlite_datamodel_connector.rs | 5 + psl/psl-core/src/builtin_connectors/utils.rs | 1 + psl/psl-core/src/common/preview_features.rs | 10 +- .../src/configuration/configuration_struct.rs | 1 + psl/psl-core/src/configuration/datasource.rs | 15 ++- psl/psl-core/src/configuration/env_vars.rs | 5 + psl/psl-core/src/configuration/generator.rs | 8 +- psl/psl-core/src/datamodel_connector.rs | 8 +- .../src/datamodel_connector/capabilities.rs | 3 +- .../src/datamodel_connector/completions.rs | 3 +- .../datamodel_connector/constraint_names.rs | 3 +- .../datamodel_connector/empty_connector.rs | 3 +- .../src/datamodel_connector/filters.rs | 2 + .../src/datamodel_connector/native_types.rs | 11 +- .../src/datamodel_connector/relation_mode.rs | 2 +- .../datamodel_connector/walker_ext_traits.rs | 2 +- psl/psl-core/src/lib.rs | 16 ++- psl/psl-core/src/mcf.rs | 2 + psl/psl-core/src/mcf/generator.rs | 2 + psl/psl-core/src/mcf/source.rs | 5 + psl/psl-core/src/reformat.rs | 8 +- .../src/validate/datasource_loader.rs | 8 +- psl/psl-core/src/validate/generator_loader.rs | 7 +- .../validations/composite_types.rs | 2 +- .../validations/constraint_namespace.rs | 4 +- .../validation_pipeline/validations/enums.rs | 2 +- .../validation_pipeline/validations/fields.rs | 6 +- .../validation_pipeline/validations/models.rs | 3 +- .../validation_pipeline/validations/names.rs | 3 +- .../validations/relation_fields.rs | 2 +- .../validations/relations.rs | 6 +- .../relations/many_to_many/implicit.rs | 1 + .../validations/relations/one_to_one.rs | 1 + .../validations/relations/visited_relation.rs | 2 +- psl/psl/Cargo.toml | 2 + psl/psl/README.md | 2 +- psl/psl/src/lib.rs | 8 +- psl/psl/tests/config/sources.rs | 2 +- psl/psl/tests/validation_tests.rs | 4 +- psl/schema-ast/src/ast.rs | 11 +- psl/schema-ast/src/ast/argument.rs | 8 +- psl/schema-ast/src/ast/attribute.rs | 2 +- psl/schema-ast/src/ast/comment.rs | 2 + psl/schema-ast/src/ast/composite_type.rs | 6 +- psl/schema-ast/src/ast/enum.rs | 4 +- psl/schema-ast/src/ast/expression.rs | 7 +- psl/schema-ast/src/ast/field.rs | 5 +- psl/schema-ast/src/ast/find_at_position.rs | 2 +- .../src/ast/find_at_position/attribute.rs | 7 +- .../src/ast/find_at_position/enum.rs | 2 + .../src/ast/find_at_position/expression.rs | 4 +- psl/schema-ast/src/ast/generator_config.rs | 2 + psl/schema-ast/src/ast/identifier.rs | 2 + psl/schema-ast/src/ast/indentation_type.rs | 2 +- psl/schema-ast/src/ast/model.rs | 4 +- psl/schema-ast/src/ast/newline_type.rs | 2 +- psl/schema-ast/src/ast/source_config.rs | 2 + psl/schema-ast/src/lib.rs | 10 +- psl/schema-ast/src/parser/parse_comments.rs | 2 + .../src/parser/parse_composite_type.rs | 1 + psl/schema-ast/src/parser/parse_enum.rs | 1 + psl/schema-ast/src/parser/parse_expression.rs | 5 + psl/schema-ast/src/parser/parse_field.rs | 1 + psl/schema-ast/src/parser/parse_model.rs | 1 + psl/schema-ast/src/parser/parse_schema.rs | 3 +- .../src/parser/parse_source_and_generator.rs | 1 + psl/schema-ast/src/parser/parse_types.rs | 1 + psl/schema-ast/src/parser/parse_view.rs | 1 + psl/schema-ast/src/reformat.rs | 3 +- psl/schema-ast/src/renderer.rs | 1 + psl/schema-ast/src/renderer/table.rs | 6 +- psl/schema-ast/src/source_file.rs | 6 +- quaint/Cargo.toml | 100 +++++++++-------- quaint/src/ast.rs | 2 +- quaint/src/error/mod.rs | 10 +- quaint/src/lib.rs | 4 +- quaint/src/macros.rs | 11 +- quaint/src/prelude.rs | 1 + query-compiler/query-compiler-wasm/Cargo.toml | 2 +- .../query-compiler-wasm/src/compiler.rs | 30 +---- query-compiler/query-compiler-wasm/src/lib.rs | 10 +- .../query-compiler-wasm/src/panic.rs | 18 +++ .../query-compiler-wasm/src/params.rs | 1 + .../connectors/query-connector/Cargo.toml | 2 +- .../query-connector/src/interface.rs | 4 + query-engine/core/Cargo.toml | 14 ++- query-engine/core/src/lib.rs | 20 +++- query-engine/query-structure/Cargo.toml | 10 +- .../src/aggregate_selection.rs | 3 +- .../query-structure/src/composite_type.rs | 4 +- query-engine/query-structure/src/convert.rs | 3 +- .../query-structure/src/default_value.rs | 11 +- query-engine/query-structure/src/distinct.rs | 2 +- query-engine/query-structure/src/error.rs | 1 + .../query-structure/src/field/composite.rs | 8 +- query-engine/query-structure/src/field/mod.rs | 10 +- .../query-structure/src/field/relation.rs | 9 +- .../query-structure/src/field/scalar.rs | 9 +- .../query-structure/src/field_selection.rs | 17 ++- query-engine/query-structure/src/fields.rs | 1 + .../query-structure/src/filter/composite.rs | 1 + .../query-structure/src/filter/into_filter.rs | 1 + .../query-structure/src/filter/json.rs | 2 + .../query-structure/src/filter/mod.rs | 1 + .../query-structure/src/filter/record.rs | 2 + .../query-structure/src/filter/relation.rs | 6 +- .../src/filter/scalar/condition/mod.rs | 1 + .../src/filter/scalar/condition/value.rs | 1 + .../query-structure/src/filter/scalar/mod.rs | 2 +- .../src/filter/scalar/projection.rs | 6 +- .../src/internal_data_model.rs | 2 +- .../query-structure/src/internal_enum.rs | 4 +- query-engine/query-structure/src/lib.rs | 7 +- query-engine/query-structure/src/model.rs | 4 +- .../src/native_type_instance.rs | 3 +- query-engine/query-structure/src/order_by.rs | 10 +- .../query-structure/src/parent_container.rs | 10 +- .../query-structure/src/prisma_value_ext.rs | 1 + .../src/projections/model_projection.rs | 3 +- .../query-structure/src/query_arguments.rs | 5 +- query-engine/query-structure/src/record.rs | 6 +- query-engine/query-structure/src/relation.rs | 5 +- .../query-structure/src/selection_result.rs | 8 +- .../query-structure/src/write_args.rs | 4 +- query-engine/query-structure/src/zipper.rs | 6 +- query-engine/schema/Cargo.toml | 1 - 185 files changed, 881 insertions(+), 380 deletions(-) create mode 100644 libs/lazy-race/Cargo.toml create mode 100644 libs/lazy-race/src/lib.rs create mode 100644 query-compiler/query-compiler-wasm/src/panic.rs diff --git a/Cargo.lock b/Cargo.lock index 52ec7ccfd976..a4a916b62af1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -958,7 +958,7 @@ name = "crosstarget-utils" version = "0.1.0" dependencies = [ "chrono", - "derive_more", + "derive_more 2.0.1", "enumflags2", "futures", "js-sys", @@ -1096,7 +1096,7 @@ dependencies = [ "base64 0.22.1", "expect-test", "indoc", - "itertools 0.13.0", + "itertools 0.14.0", "psl", "regex", ] @@ -1135,6 +1135,26 @@ dependencies = [ "syn 2.0.104", ] +[[package]] +name = "derive_more" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "093242cf7570c207c83073cf82f79706fe7b8317e98620a47d5be7c3d8497678" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.104", +] + [[package]] name = "diagnostics" version = "0.1.0" @@ -1188,7 +1208,7 @@ dependencies = [ "flate2", "indexmap 2.10.0", "indoc", - "itertools 0.13.0", + "itertools 0.14.0", "pretty_assertions", "psl", "query-structure", @@ -1761,6 +1781,8 @@ dependencies = [ "allocator-api2", "equivalent", "foldhash", + "rustc-std-workspace-alloc", + "serde", ] [[package]] @@ -2262,6 +2284,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.14.0" +source = "git+https://github.com/aqrln/itertools?branch=hashbrown#a57809b9e0784e8b71a0e2d66c1e4942e57a7d9b" +dependencies = [ + "either", + "hashbrown 0.15.2", +] + [[package]] name = "itoa" version = "1.0.9" @@ -2321,6 +2352,13 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "lazy-race" +version = "0.1.0" +dependencies = [ + "once_cell", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -2699,7 +2737,7 @@ dependencies = [ "bson", "chrono", "derivative", - "derive_more", + "derive_more 0.99.20", "flate2", "futures-core", "futures-executor", @@ -2766,10 +2804,10 @@ dependencies = [ "bigdecimal", "bson", "chrono", - "derive_more", + "derive_more 2.0.1", "futures", "indexmap 2.10.0", - "itertools 0.13.0", + "itertools 0.14.0", "mongodb", "mongodb-client", "pretty_assertions", @@ -2803,7 +2841,7 @@ dependencies = [ "expect-test", "futures", "indoc", - "itertools 0.13.0", + "itertools 0.14.0", "mongodb", "mongodb-client", "mongodb-schema-describer", @@ -3278,9 +3316,9 @@ dependencies = [ "diagnostics", "either", "enumflags2", + "hashbrown 0.15.2", "indexmap 2.10.0", - "itertools 0.13.0", - "rustc-hash", + "itertools 0.14.0", "schema-ast", ] @@ -3373,7 +3411,6 @@ dependencies = [ "fixedbitset", "hashbrown 0.15.2", "indexmap 2.10.0", - "serde", ] [[package]] @@ -3592,7 +3629,7 @@ dependencies = [ name = "prisma-metrics" version = "0.1.0" dependencies = [ - "derive_more", + "derive_more 2.0.1", "expect-test", "futures", "metrics", @@ -3695,9 +3732,11 @@ dependencies = [ "diagnostics", "either", "enumflags2", + "hashbrown 0.15.2", "hex", "indoc", - "itertools 0.13.0", + "itertools 0.14.0", + "lazy-race", "lsp-types", "parser-database", "prisma-value", @@ -3769,7 +3808,7 @@ dependencies = [ "getrandom 0.2.11", "hex", "indoc", - "itertools 0.13.0", + "itertools 0.14.0", "lru-cache", "mobc", "mysql_async", @@ -3857,7 +3896,7 @@ dependencies = [ "bon", "indexmap 2.10.0", "insta", - "itertools 0.13.0", + "itertools 0.14.0", "pretty", "psl", "quaint", @@ -3894,6 +3933,7 @@ name = "query-compiler-wasm" version = "0.1.0" dependencies = [ "build-utils", + "hashbrown 0.15.2", "js-sys", "psl", "quaint", @@ -3920,7 +3960,7 @@ dependencies = [ "chrono", "futures", "indexmap 2.10.0", - "itertools 0.13.0", + "itertools 0.14.0", "prisma-value", "query-structure", "serde", @@ -3943,11 +3983,11 @@ dependencies = [ "crossbeam-channel", "crosstarget-utils", "cuid", - "derive_more", + "derive_more 2.0.1", "enumflags2", "futures", "indexmap 2.10.0", - "itertools 0.13.0", + "itertools 0.14.0", "lru 0.7.8", "petgraph", "prisma-metrics", @@ -4114,7 +4154,7 @@ dependencies = [ "futures", "indoc", "insta", - "itertools 0.13.0", + "itertools 0.14.0", "paste", "prisma-metrics", "prisma-value", @@ -4174,8 +4214,9 @@ dependencies = [ "chrono", "cuid", "getrandom 0.2.11", + "hashbrown 0.15.2", "indexmap 2.10.0", - "itertools 0.13.0", + "itertools 0.14.0", "nanoid", "prisma-value", "psl", @@ -4214,7 +4255,7 @@ dependencies = [ "indexmap 2.10.0", "indoc", "insta", - "itertools 0.13.0", + "itertools 0.14.0", "jsonrpc-core", "log", "nom", @@ -4542,7 +4583,7 @@ dependencies = [ "graphql-parser", "indexmap 2.10.0", "insta", - "itertools 0.13.0", + "itertools 0.14.0", "mongodb-query-connector", "prisma-value", "psl", @@ -4719,6 +4760,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-std-workspace-alloc" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d441c3b2ebf55cebf796bfdc265d67fa09db17b7bb6bd4be75c509e1e8fec3" + [[package]] name = "rustc_version" version = "0.4.0" @@ -4825,7 +4872,6 @@ dependencies = [ "codspeed-criterion-compat", "psl", "query-structure", - "rustc-hash", ] [[package]] @@ -5335,7 +5381,7 @@ dependencies = [ "enumflags2", "expect-test", "indoc", - "itertools 0.13.0", + "itertools 0.14.0", "pretty_assertions", "psl", "quaint", @@ -5389,7 +5435,7 @@ version = "0.1.0" dependencies = [ "bigdecimal", "chrono", - "itertools 0.13.0", + "itertools 0.14.0", "prisma-value", "psl", "quaint", @@ -5412,7 +5458,7 @@ dependencies = [ "cuid", "expect-test", "futures", - "itertools 0.13.0", + "itertools 0.14.0", "panic-utils", "prisma-value", "psl", @@ -5448,7 +5494,7 @@ dependencies = [ "expect-test", "indexmap 2.10.0", "indoc", - "itertools 0.13.0", + "itertools 0.14.0", "prisma-value", "psl", "quaint", @@ -5482,7 +5528,7 @@ dependencies = [ "expect-test", "indexmap 2.10.0", "indoc", - "itertools 0.13.0", + "itertools 0.14.0", "pretty_assertions", "prisma-value", "psl", @@ -5709,10 +5755,10 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" name = "telemetry" version = "0.1.0" dependencies = [ - "ahash 0.8.11", "crosstarget-utils", - "derive_more", + "derive_more 2.0.1", "enumflags2", + "hashbrown 0.15.2", "insta", "rand 0.8.5", "serde", @@ -6391,7 +6437,7 @@ name = "user-facing-errors" version = "0.1.0" dependencies = [ "indoc", - "itertools 0.13.0", + "itertools 0.14.0", "panic-utils", "quaint", "serde", diff --git a/Cargo.toml b/Cargo.toml index 3ea1c4763edc..0a788acd55de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,39 +48,44 @@ level = "warn" check-cfg = ['cfg(wasm_bindgen_unstable_test_coverage)', 'cfg(debug_assert)'] [workspace.dependencies] -ahash = "0.8" -anyhow = "1" +anyhow = { version = "1", default-features = false } async-trait = "0.1" barrel = { git = "https://github.com/prisma/barrel.git", branch = "mssql-support" } -base64 = "0.22" +base64 = { version = "0.22", default-features = false, features = ["alloc"] } bigdecimal = "0.3" bitflags = "2" -bit-vec = "0.6" -bon = "3" +bit-vec = { version = "0.6", default-features = false } +bon = { version = "3", default-features = false, features = ["alloc"] } bson = "2" -bytes = "1" +bytes = { version = "1", default-features = false } byteorder = { version = "1", default-features = false } cfg-if = "1" -chrono = "0.4" +chrono = { version = "0.4", default-features = false, features = ["alloc"] } colored = "3" concat-idents = "1" connection-string = "0.2" convert_case = "0.6" -crossbeam-channel = "0.5" +crossbeam-channel = { version = "0.5", default-features = false } cuid = { git = "https://github.com/prisma/cuid-rust", branch = "v1.3.3-wasm32-unknown-unknown" } -derive_more = "0.99" -either = "1" +derive_more = { version = "2", default-features = false } +either = { version = "1", default-features = false } enumflags2 = "0.7" env_logger = "0.11" -futures = "0.3" +futures = { version = "0.3", default-features = false, features = [ + "alloc", + "async-await", +] } getrandom = "0.2" graphql-parser = { git = "https://github.com/prisma/graphql-parser" } +hashbrown = "0.15" heck = "0.4" -hex = "0.4" +hex = { version = "0.4", default-features = false, features = ["alloc"] } hyper = "0.14" indoc = "2" -indexmap = "2" -itertools = "0.13" +indexmap = { version = "2", default-features = false } +itertools = { git = "https://github.com/aqrln/itertools", branch = "hashbrown", default-features = false, features = [ + "hashbrown", +] } jsonrpc-core = "17" log = "0.4" lru = "0.7" @@ -105,27 +110,39 @@ napi = { version = "2", default-features = false, features = [ ] } napi-derive = "2" native-tls = "0.2" -nom = "7" +nom = { version = "7", default-features = false, features = ["alloc"] } num_cpus = "1" +once_cell = { version = "1", default-features = false, features = ["alloc"] } parking_lot = "0.12" parse-hyperlinks = "0.23" paste = "1" -percent-encoding = "2" -pest = "2" -pest_derive = "2" -petgraph = "0.8" +percent-encoding = { version = "2", default-features = false, features = [ + "alloc", +] } +pest = { version = "2", default-features = false, features = ["memchr"] } +pest_derive = { version = "2", default-features = false } +petgraph = { version = "0.8", default-features = false } pin-project = "1" postgres-native-tls = { git = "https://github.com/prisma/rust-postgres", branch = "pgbouncer-mode" } postgres-types = { git = "https://github.com/prisma/rust-postgres", branch = "pgbouncer-mode" } pretty = "0.12" -rustc-hash = "1" -rand = "0.8" -regex = "1" +rand = { version = "0.8", default-features = false, features = [ + "alloc", + "getrandom", +] } +regex = { version = "1", default-features = false, features = [ + "perf", + "unicode", +] } reqwest = "0.11" rusqlite = "0.32" sha2 = "0.10" -serde = { version = "1", features = ["derive"] } -serde_json = { version = "1", features = [ +serde = { version = "1", default-features = false, features = [ + "alloc", + "derive", +] } +serde_json = { version = "1", default-features = false, features = [ + "alloc", "float_roundtrip", "preserve_order", "raw_value", @@ -146,21 +163,35 @@ tokio-postgres = { git = "https://github.com/prisma/rust-postgres", branch = "pg tokio-tungstenite = "0.26" tokio-util = "0.7" toml = "0.5" -tracing = "0.1" -tracing-core = "0.1" +tracing = { version = "0.1", default-features = false, features = [ + "attributes", +] } +tracing-core = { version = "0.1", default-features = false } tracing-error = "0.2" -tracing-subscriber = "0.3" -tracing-futures = "0.2" +tracing-subscriber = { version = "0.3", default-features = false, features = [ + "alloc", + "smallvec", + "tracing-log", +] } +tracing-futures = { version = "0.2", default-features = false, features = [ + "std-future", +] } tsify = { version = "0.5", default-features = false, features = ["js"] } -thiserror = "2" -url = "2" -ulid = "1" -uuid = { version = "1", features = ["v4", "v7", "js"] } +thiserror = { version = "2", default-features = false } +url = { version = "2", default-features = false } +ulid = { version = "1", default-features = false, features = ["rand"] } +uuid = { version = "1", default-features = false, features = [ + "v4", + "v7", + "js", +] } versions = "6" -js-sys = "0.3" -wasm-bindgen = "0.2" -wasm-bindgen-futures = "0.4" +js-sys = { version = "0.3", default-features = false } +wasm-bindgen = { version = "0.2", default-features = false, features = [ + "msrv", +] } +wasm-bindgen-futures = { version = "0.4", default-features = false } wasm-logger = "0.2" # build dependencies @@ -205,7 +236,8 @@ query-engine-common.path = "./libs/query-engine-common" shared-wasm.path = "./libs/shared-wasm" driver-adapters.path = "./libs/driver-adapters" sql-ddl.path = "./libs/sql-ddl" -query-template.path = "libs/query-template" +query-template.path = "./libs/query-template" +lazy-race.path = "./libs/lazy-race" psl.path = "./psl/psl" psl-core.path = "./psl/psl-core" diff --git a/libs/crosstarget-utils/Cargo.toml b/libs/crosstarget-utils/Cargo.toml index 67bea4f7cc08..d7f89b510480 100644 --- a/libs/crosstarget-utils/Cargo.toml +++ b/libs/crosstarget-utils/Cargo.toml @@ -22,4 +22,4 @@ chrono = { workspace = true, features = ["wasmbind"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio.workspace = true regex.workspace = true -chrono = { workspace = true } +chrono = { workspace = true, features = ["now"] } diff --git a/libs/crosstarget-utils/src/common/datetime.rs b/libs/crosstarget-utils/src/common/datetime.rs index 8f6e9dac1635..423033efb4f2 100644 --- a/libs/crosstarget-utils/src/common/datetime.rs +++ b/libs/crosstarget-utils/src/common/datetime.rs @@ -3,10 +3,17 @@ pub struct DateTime(chrono::DateTime); impl DateTime { + #[cfg(not(target_arch = "wasm32"))] fn now() -> Self { Self(chrono::Utc::now()) } + #[cfg(target_arch = "wasm32")] + fn now() -> Self { + let now = js_sys::Date::new_0(); + Self(chrono::DateTime::from(now)) + } + fn format(&self, format_str: &str) -> String { self.0.format(format_str).to_string() } diff --git a/libs/lazy-race/Cargo.toml b/libs/lazy-race/Cargo.toml new file mode 100644 index 000000000000..9c7be6de42f0 --- /dev/null +++ b/libs/lazy-race/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "lazy-race" +version = "0.1.0" +edition.workspace = true + +[dependencies] +once_cell = { workspace = true, features = ["alloc", "race"] } + +[lints] +workspace = true diff --git a/libs/lazy-race/src/lib.rs b/libs/lazy-race/src/lib.rs new file mode 100644 index 000000000000..7ab772a51552 --- /dev/null +++ b/libs/lazy-race/src/lib.rs @@ -0,0 +1,57 @@ +#![no_std] + +extern crate alloc; + +use alloc::boxed::Box; +use core::{fmt, ops::Deref}; + +use once_cell::race::OnceBox; + +/// An alternative to `std::sync::LazyLock` or `once_cell::sync::Lazy` that does +/// not require locking and works without a dependency on `std` or +/// `critical_section`. +/// +/// Unlike those types, it requires the initializer function to be `Fn() -> T` +/// and not `FnOnce() -> T`, and has slightly different semantics. If multiple +/// threads try to obtain the value before a `LazyRace` is initialized, all of +/// them will compute it, but only the first one to finish will store the value. +/// Other results will be discarded and replaced with the result produced by the +/// winning thread. Once a value has been stored, it will not be recomputed +/// anymore, and all subsequent concurrent accesses will return the cached +/// value. +pub struct LazyRace T> { + cell: OnceBox, + init: F, +} + +impl fmt::Debug for LazyRace { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("LazyRace") + .field("cell", &self.cell) + .field("init", &"..") + .finish() + } +} + +impl LazyRace { + pub const fn new(f: F) -> LazyRace { + LazyRace { + cell: OnceBox::new(), + init: f, + } + } +} + +impl T> LazyRace { + pub fn force(this: &Self) -> &T { + this.cell.get_or_init(|| Box::new((this.init)())) + } +} + +impl T> Deref for LazyRace { + type Target = T; + + fn deref(&self) -> &Self::Target { + LazyRace::force(self) + } +} diff --git a/libs/prisma-value/src/arithmetic.rs b/libs/prisma-value/src/arithmetic.rs index 83a9e1bbb779..544e4e7a6564 100644 --- a/libs/prisma-value/src/arithmetic.rs +++ b/libs/prisma-value/src/arithmetic.rs @@ -1,6 +1,6 @@ //! Note: Only number operations are implemented at the moment. use super::*; -use std::ops::*; +use core::ops::*; /// Used right now to reduce code duplication, probably needs to be scrapped once we need anything beyond that. macro_rules! number_operation { diff --git a/libs/prisma-value/src/error.rs b/libs/prisma-value/src/error.rs index 9e5512ea156b..74e14546b3e8 100644 --- a/libs/prisma-value/src/error.rs +++ b/libs/prisma-value/src/error.rs @@ -1,6 +1,5 @@ -use std::borrow::Cow; -use std::error::Error; -use std::fmt::Display; +use alloc::borrow::Cow; +use core::{error::Error, fmt::Display}; #[derive(Debug)] pub struct ConversionFailure { @@ -11,7 +10,7 @@ pub struct ConversionFailure { impl Error for ConversionFailure {} impl Display for ConversionFailure { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "Could not convert from `{}` to `{}`", self.from, self.to) } } diff --git a/libs/prisma-value/src/lib.rs b/libs/prisma-value/src/lib.rs index 1f213e857607..b3df52a23886 100644 --- a/libs/prisma-value/src/lib.rs +++ b/libs/prisma-value/src/lib.rs @@ -1,9 +1,22 @@ +#![no_std] + +#[macro_use] +extern crate alloc; + pub mod arithmetic; mod error; mod raw_json; mod tagged; +use alloc::{ + borrow::{Cow, ToOwned}, + boxed::Box, + string::{String, ToString}, + vec::Vec, +}; +use core::{fmt, str::FromStr}; + use base64::prelude::*; use bigdecimal::{BigDecimal, FromPrimitive, ToPrimitive}; use chrono::prelude::*; @@ -11,14 +24,13 @@ use serde::de::Unexpected; use serde::ser::SerializeMap; use serde::{Deserialize, Deserializer, Serialize, ser::Serializer}; use serde_json::json; -use std::{borrow::Cow, convert::TryFrom, fmt, str::FromStr}; use uuid::Uuid; pub use error::ConversionFailure; pub use raw_json::RawJson; pub use tagged::TaggedPrismaValue; -pub type PrismaValueResult = std::result::Result; +pub type PrismaValueResult = core::result::Result; pub type PrismaListValue = Vec; #[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize, PartialOrd, Ord)] @@ -103,7 +115,7 @@ pub enum PrismaValueType { Enum(String), } -impl std::fmt::Display for PrismaValueType { +impl core::fmt::Display for PrismaValueType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { PrismaValueType::Any => write!(f, "Any"), diff --git a/libs/prisma-value/src/raw_json.rs b/libs/prisma-value/src/raw_json.rs index 83db97658459..59193ca7916d 100644 --- a/libs/prisma-value/src/raw_json.rs +++ b/libs/prisma-value/src/raw_json.rs @@ -1,3 +1,5 @@ +use alloc::{borrow::ToOwned, string::String}; + use serde::Serialize; use serde_json::value::RawValue; diff --git a/libs/prisma-value/src/tagged.rs b/libs/prisma-value/src/tagged.rs index 514986aaaa3d..d607b55d748f 100644 --- a/libs/prisma-value/src/tagged.rs +++ b/libs/prisma-value/src/tagged.rs @@ -1,3 +1,5 @@ +use alloc::string::ToString; + use serde::{Serialize, ser::SerializeMap}; use serde_json::json; @@ -49,11 +51,11 @@ impl<'a> From<&'a PrismaValue> for TaggedPrismaValue<'a> { } struct TaggedPrismaValueSliceIter<'a> { - iter: std::slice::Iter<'a, PrismaValue>, + iter: core::slice::Iter<'a, PrismaValue>, } impl<'a> TaggedPrismaValueSliceIter<'a> { - fn new(iter: std::slice::Iter<'a, PrismaValue>) -> Self { + fn new(iter: core::slice::Iter<'a, PrismaValue>) -> Self { Self { iter } } } diff --git a/libs/query-template/src/fragment.rs b/libs/query-template/src/fragment.rs index de92f46ccc2a..5990a2c8a9b6 100644 --- a/libs/query-template/src/fragment.rs +++ b/libs/query-template/src/fragment.rs @@ -1,4 +1,4 @@ -use std::borrow::Cow; +use alloc::{borrow::Cow, string::String}; use serde::Serialize; diff --git a/libs/query-template/src/lib.rs b/libs/query-template/src/lib.rs index 9e9760953e08..0336e9e03c18 100644 --- a/libs/query-template/src/lib.rs +++ b/libs/query-template/src/lib.rs @@ -1,3 +1,7 @@ +#![no_std] + +extern crate alloc; + mod fragment; mod placeholder; mod template; diff --git a/libs/query-template/src/placeholder.rs b/libs/query-template/src/placeholder.rs index 1b3823032d66..749610213a7e 100644 --- a/libs/query-template/src/placeholder.rs +++ b/libs/query-template/src/placeholder.rs @@ -1,6 +1,6 @@ +use core::fmt::{self, Write}; + use serde::Serialize; -use std::fmt; -use std::fmt::Write; #[derive(Clone, Debug, Serialize)] #[serde(rename_all = "camelCase")] diff --git a/libs/query-template/src/template.rs b/libs/query-template/src/template.rs index b44f63ac71cd..ed3d6a18b6be 100644 --- a/libs/query-template/src/template.rs +++ b/libs/query-template/src/template.rs @@ -1,7 +1,8 @@ +use alloc::{string::String, vec::Vec}; +use core::fmt::{self, Debug}; + use crate::fragment::Fragment; use crate::placeholder::PlaceholderFormat; -use std::fmt; -use std::fmt::Debug; #[derive(Debug)] pub struct QueryTemplate

{ diff --git a/libs/shared-wasm/src/lib.rs b/libs/shared-wasm/src/lib.rs index d6ec64893efe..ab136473ddd7 100644 --- a/libs/shared-wasm/src/lib.rs +++ b/libs/shared-wasm/src/lib.rs @@ -1,3 +1,5 @@ +#![no_std] + use serde_wasm_bindgen::Serializer; // - `serialize_missing_as_null` is required to make sure that "empty" values (e.g., `None` and `()`) diff --git a/libs/telemetry/Cargo.toml b/libs/telemetry/Cargo.toml index 283850533823..d0b5a1e30cf7 100644 --- a/libs/telemetry/Cargo.toml +++ b/libs/telemetry/Cargo.toml @@ -4,7 +4,7 @@ name = "telemetry" version = "0.1.0" [dependencies] -ahash.workspace = true +hashbrown = { workspace = true, features = ["serde"] } serde.workspace = true serde_json.workspace = true thiserror.workspace = true diff --git a/libs/telemetry/src/collector.rs b/libs/telemetry/src/collector.rs index d7344279e670..185333274301 100644 --- a/libs/telemetry/src/collector.rs +++ b/libs/telemetry/src/collector.rs @@ -1,7 +1,7 @@ use std::{borrow::Cow, time::Duration}; -use ahash::{HashMap, HashMapExt}; use crosstarget_utils::time::{ElapsedTimeCounter, SystemTime}; +use hashbrown::HashMap; #[cfg(test)] use serde::Serialize; diff --git a/libs/telemetry/src/exporter.rs b/libs/telemetry/src/exporter.rs index 2a8bd9f2574e..b1c4d7b416f8 100644 --- a/libs/telemetry/src/exporter.rs +++ b/libs/telemetry/src/exporter.rs @@ -1,7 +1,7 @@ use std::{borrow::Cow, fmt::Debug, str::FromStr}; -use ahash::{HashMap, HashMapExt}; use enumflags2::{BitFlags, bitflags}; +use hashbrown::HashMap; use serde::Serialize; use tokio::sync::{ mpsc::{self, UnboundedSender}, diff --git a/psl/diagnostics/src/collection.rs b/psl/diagnostics/src/collection.rs index 0d1d0d3fa533..c08e1ec589d2 100644 --- a/psl/diagnostics/src/collection.rs +++ b/psl/diagnostics/src/collection.rs @@ -1,3 +1,5 @@ +use alloc::{string::String, vec::Vec}; + use super::DatamodelError; use crate::warning::DatamodelWarning; @@ -46,32 +48,32 @@ impl Diagnostics { pub fn to_result(&mut self) -> Result<(), Diagnostics> { if self.has_errors() { - Err(std::mem::take(self)) + Err(core::mem::take(self)) } else { Ok(()) } } pub fn to_pretty_string(&self, file_name: &str, datamodel_string: &str) -> String { - let mut message: Vec = Vec::new(); + let mut message = String::new(); for err in self.errors() { err.pretty_print(&mut message, file_name, datamodel_string) .expect("printing datamodel error"); } - String::from_utf8_lossy(&message).into_owned() + message } pub fn warnings_to_pretty_string(&self, file_name: &str, datamodel_string: &str) -> String { - let mut message: Vec = Vec::new(); + let mut message = String::new(); for warn in self.warnings() { warn.pretty_print(&mut message, file_name, datamodel_string) .expect("printing datamodel warning"); } - String::from_utf8_lossy(&message).into_owned() + message } } diff --git a/psl/diagnostics/src/error.rs b/psl/diagnostics/src/error.rs index dd3eef37823e..f807158fa789 100644 --- a/psl/diagnostics/src/error.rs +++ b/psl/diagnostics/src/error.rs @@ -1,10 +1,14 @@ +use alloc::{ + borrow::{Cow, ToOwned}, + string::{String, ToString}, +}; + use colored::{ColoredString, Colorize}; use crate::{ Span, pretty_print::{DiagnosticColorer, pretty_print}, }; -use std::borrow::Cow; #[derive(Debug, Clone)] pub struct DatamodelError { @@ -431,7 +435,7 @@ impl DatamodelError { &self.message } - pub fn pretty_print(&self, f: &mut dyn std::io::Write, file_name: &str, text: &str) -> std::io::Result<()> { + pub fn pretty_print(&self, f: &mut dyn core::fmt::Write, file_name: &str, text: &str) -> core::fmt::Result { pretty_print( f, file_name, diff --git a/psl/diagnostics/src/lib.rs b/psl/diagnostics/src/lib.rs index 0d47d2c3c975..7a4beac87459 100644 --- a/psl/diagnostics/src/lib.rs +++ b/psl/diagnostics/src/lib.rs @@ -1,3 +1,8 @@ +#![no_std] + +#[macro_use] +extern crate alloc; + mod collection; mod error; mod native_type_error_factory; diff --git a/psl/diagnostics/src/native_type_error_factory.rs b/psl/diagnostics/src/native_type_error_factory.rs index 826406987b1e..2ed73403cdd3 100644 --- a/psl/diagnostics/src/native_type_error_factory.rs +++ b/psl/diagnostics/src/native_type_error_factory.rs @@ -1,3 +1,5 @@ +use alloc::string::String; + use crate::{DatamodelError, Span}; pub struct NativeTypeErrorFactory { diff --git a/psl/diagnostics/src/pretty_print.rs b/psl/diagnostics/src/pretty_print.rs index fb86c568d7d1..dcc2d58c42de 100644 --- a/psl/diagnostics/src/pretty_print.rs +++ b/psl/diagnostics/src/pretty_print.rs @@ -1,4 +1,5 @@ use crate::Span; +use alloc::vec::Vec; use colored::{ColoredString, Colorize}; pub trait DiagnosticColorer { @@ -10,13 +11,13 @@ pub trait DiagnosticColorer { /// Given the datamodel text representation, pretty prints an error or warning, including /// the offending portion of the source code, for human-friendly reading. pub(crate) fn pretty_print( - f: &mut dyn std::io::Write, + f: &mut dyn core::fmt::Write, file_name: &str, text: &str, span: Span, description: &str, colorer: &'static dyn DiagnosticColorer, -) -> std::io::Result<()> { +) -> core::fmt::Result { let start_line_number = text[..span.start].matches('\n').count(); let end_line_number = text[..span.end].matches('\n').count(); let file_lines = text.split('\n').collect::>(); @@ -28,7 +29,7 @@ pub(crate) fn pretty_print( let line = &file_lines[start_line_number]; let start_in_line = span.start - bytes_in_line_before; - let end_in_line = std::cmp::min(start_in_line + (span.end - span.start), line.len()); + let end_in_line = core::cmp::min(start_in_line + (span.end - span.start), line.len()); let prefix = &line[..start_in_line]; let offending = colorer.primary_color(&line[start_in_line..end_in_line]).bold(); diff --git a/psl/diagnostics/src/warning.rs b/psl/diagnostics/src/warning.rs index 3d4b94b05980..bf064bbb20bd 100644 --- a/psl/diagnostics/src/warning.rs +++ b/psl/diagnostics/src/warning.rs @@ -2,9 +2,13 @@ use crate::{ Span, pretty_print::{DiagnosticColorer, pretty_print}, }; +use alloc::{ + borrow::ToOwned, + string::{String, ToString}, +}; use colored::{ColoredString, Colorize}; +use core::fmt::Display; use indoc::indoc; -use std::fmt::Display; /// A non-fatal warning emitted by the schema parser. /// For fancy printing, please use the `pretty_print_error` function. @@ -100,7 +104,7 @@ impl DatamodelWarning { self.span } - pub fn pretty_print(&self, f: &mut dyn std::io::Write, file_name: &str, text: &str) -> std::io::Result<()> { + pub fn pretty_print(&self, f: &mut dyn core::fmt::Write, file_name: &str, text: &str) -> core::fmt::Result { pretty_print( f, file_name, diff --git a/psl/parser-database/Cargo.toml b/psl/parser-database/Cargo.toml index b9a188cd3917..fa3d638335c0 100644 --- a/psl/parser-database/Cargo.toml +++ b/psl/parser-database/Cargo.toml @@ -10,4 +10,4 @@ indexmap.workspace = true enumflags2.workspace = true itertools.workspace = true either.workspace = true -rustc-hash.workspace = true +hashbrown.workspace = true diff --git a/psl/parser-database/src/attributes.rs b/psl/parser-database/src/attributes.rs index 10bd91edb51e..7217b3e55773 100644 --- a/psl/parser-database/src/attributes.rs +++ b/psl/parser-database/src/attributes.rs @@ -16,9 +16,10 @@ use crate::{ }, walkers::RelationFieldId, }; +use alloc::{borrow::Cow, string::String, vec::Vec}; +use core::{cell::Cell, fmt::Display}; use diagnostics::Span; use itertools::Itertools; -use std::{borrow::Cow, cell::Cell, fmt::Display}; pub(super) fn resolve_attributes(ctx: &mut Context<'_>) { for rfid in ctx.types.iter_relation_field_ids() { @@ -1134,7 +1135,7 @@ fn format_fields_in_error_with_leading_word<'a>( F: Display, I: IntoIterator>, { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let Some(iter) = self.0.take().map(<_>::into_iter) else { panic!("`format_fields_in_error_with_leading_word` result can only be formatted once") }; @@ -1149,7 +1150,7 @@ fn format_fields_in_error_with_leading_word<'a>( struct Field(D); impl Display for Field { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "`{}`", self.0) } } diff --git a/psl/parser-database/src/attributes/default.rs b/psl/parser-database/src/attributes/default.rs index 8410c3e7d069..8704672672d0 100644 --- a/psl/parser-database/src/attributes/default.rs +++ b/psl/parser-database/src/attributes/default.rs @@ -1,3 +1,5 @@ +use alloc::string::{String, ToString}; + use crate::{ DatamodelError, ScalarFieldId, StringId, ast::{self, WithName}, diff --git a/psl/parser-database/src/attributes/id.rs b/psl/parser-database/src/attributes/id.rs index 25b8cb360d67..333ff33463f1 100644 --- a/psl/parser-database/src/attributes/id.rs +++ b/psl/parser-database/src/attributes/id.rs @@ -7,7 +7,7 @@ use crate::{ context::Context, types::{FieldWithArgs, IdAttribute, IndexFieldPath, ModelAttributes, ScalarField, SortOrder}, }; -use std::borrow::Cow; +use alloc::{borrow::Cow, vec::Vec}; /// @@id on models pub(super) fn model(model_data: &mut ModelAttributes, model_id: crate::ModelId, ctx: &mut Context<'_>) { diff --git a/psl/parser-database/src/attributes/native_types.rs b/psl/parser-database/src/attributes/native_types.rs index 8ae176ab12d2..26a559409fae 100644 --- a/psl/parser-database/src/attributes/native_types.rs +++ b/psl/parser-database/src/attributes/native_types.rs @@ -1,3 +1,8 @@ +use alloc::{ + string::{String, ToString}, + vec::Vec, +}; + use crate::{ScalarFieldId, StringId, ast, context::Context}; pub(super) fn visit_model_field_native_type_attribute( diff --git a/psl/parser-database/src/attributes/shard_key.rs b/psl/parser-database/src/attributes/shard_key.rs index e29db8eb1c24..e80ca61dff7a 100644 --- a/psl/parser-database/src/attributes/shard_key.rs +++ b/psl/parser-database/src/attributes/shard_key.rs @@ -1,4 +1,4 @@ -use std::borrow::Cow; +use alloc::{borrow::Cow, vec::Vec}; use diagnostics::DatamodelError; use schema_ast::ast::{self, WithName, WithSpan}; diff --git a/psl/parser-database/src/coerce_expression.rs b/psl/parser-database/src/coerce_expression.rs index ee2b2f1d06aa..039c73fa13f8 100644 --- a/psl/parser-database/src/coerce_expression.rs +++ b/psl/parser-database/src/coerce_expression.rs @@ -1,3 +1,5 @@ +use alloc::{string::ToString, vec::Vec}; + use crate::{DatamodelError, Diagnostics, ast}; macro_rules! impl_coercions { diff --git a/psl/parser-database/src/context.rs b/psl/parser-database/src/context.rs index 0b174f3806cc..f6b754e76aba 100644 --- a/psl/parser-database/src/context.rs +++ b/psl/parser-database/src/context.rs @@ -5,8 +5,9 @@ use crate::{ DatamodelError, Diagnostics, InFile, StringId, ast, interner::StringInterner, names::Names, relations::Relations, types::Types, }; +use alloc::{string::ToString, vec::Vec}; +use hashbrown::{HashMap, HashSet}; use schema_ast::ast::{EnumValueId, Expression, WithName}; -use std::collections::{HashMap, HashSet}; /// Validation context. This is an implementation detail of ParserDatabase. It /// contains the database itself, as well as context that is discarded after @@ -350,7 +351,7 @@ impl<'db> Context<'db> { { // The arguments lists of the attribute and all nested function expressions. - let all_arguments_lists = std::iter::once(&attribute.arguments).chain( + let all_arguments_lists = core::iter::once(&attribute.arguments).chain( attribute .arguments .arguments @@ -453,7 +454,7 @@ fn iter_attributes<'a, 'ast: 'a>( }) } -impl std::ops::Index for Context<'_> { +impl core::ops::Index for Context<'_> { type Output = str; fn index(&self, index: StringId) -> &Self::Output { diff --git a/psl/parser-database/src/files.rs b/psl/parser-database/src/files.rs index c3ab72cbccfa..68f38004b962 100644 --- a/psl/parser-database/src/files.rs +++ b/psl/parser-database/src/files.rs @@ -1,7 +1,8 @@ use crate::FileId; +use alloc::{borrow::ToOwned, string::String, vec::Vec}; +use core::ops::Index; use diagnostics::Diagnostics; use schema_ast::ast; -use std::ops::Index; /// The content is a list of (file path, file source text, file AST). /// @@ -45,14 +46,14 @@ impl Files { /// Render the given diagnostics (warnings + errors) into a String. /// This method is multi-file aware. pub fn render_diagnostics(&self, diagnostics: &Diagnostics) -> String { - let mut out = Vec::new(); + let mut out = String::new(); for error in diagnostics.errors() { let (file_name, source, _) = &self[error.span().file_id]; error.pretty_print(&mut out, file_name, source.as_str()).unwrap(); } - String::from_utf8(out).unwrap() + out } /// Returns the number of files. diff --git a/psl/parser-database/src/interner.rs b/psl/parser-database/src/interner.rs index 5fbebc812f05..8128cb42f629 100644 --- a/psl/parser-database/src/interner.rs +++ b/psl/parser-database/src/interner.rs @@ -4,6 +4,8 @@ //! The StringIds returned by `intern` are only valid for this specific instance of the interner //! they were interned with. +use alloc::{borrow::ToOwned, string::String}; + use indexmap::IndexSet; #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] diff --git a/psl/parser-database/src/lib.rs b/psl/parser-database/src/lib.rs index f573bdd77f8a..da98ab4b1ace 100644 --- a/psl/parser-database/src/lib.rs +++ b/psl/parser-database/src/lib.rs @@ -1,5 +1,6 @@ #![deny(unsafe_code, rust_2018_idioms, missing_docs)] #![allow(clippy::derive_partial_eq_without_eq)] +#![no_std] //! See the docs on [ParserDatabase](./struct.ParserDatabase.html). //! @@ -26,6 +27,9 @@ //! defined with a `map:` argument or be a default, generated name if the `map:` argument is not //! provided. These usually require a datamodel connector to be defined. +#[macro_use] +extern crate alloc; + pub mod walkers; mod attributes; @@ -40,6 +44,7 @@ mod relations; mod types; use self::{context::Context, interner::StringId, relations::Relations, types::Types}; +use alloc::{borrow::ToOwned, string::String}; pub use coerce_expression::{coerce, coerce_array, coerce_opt}; pub use diagnostics::FileId; use diagnostics::{DatamodelError, Diagnostics}; @@ -223,7 +228,7 @@ impl ParserDatabase { } } -impl std::ops::Index for ParserDatabase { +impl core::ops::Index for ParserDatabase { type Output = (String, SourceFile, ast::SchemaAst); fn index(&self, index: FileId) -> &Self::Output { @@ -231,13 +236,13 @@ impl std::ops::Index for ParserDatabase { } } -impl std::fmt::Debug for ParserDatabase { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for ParserDatabase { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.write_str("ParserDatabase { ... }") } } -impl std::ops::Index for ParserDatabase { +impl core::ops::Index for ParserDatabase { type Output = str; fn index(&self, index: StringId) -> &Self::Output { diff --git a/psl/parser-database/src/names.rs b/psl/parser-database/src/names.rs index b123b19899d7..3d329904bbf1 100644 --- a/psl/parser-database/src/names.rs +++ b/psl/parser-database/src/names.rs @@ -7,8 +7,8 @@ use crate::{ ast::{self, ConfigBlockProperty, TopId, WithAttributes, WithIdentifier, WithName, WithSpan}, types::ScalarType, }; +use hashbrown::{HashMap, HashSet}; use reserved_model_names::{validate_enum_name, validate_model_name}; -use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet}; /// Resolved names for use in the validation process. #[derive(Default)] @@ -147,7 +147,7 @@ pub(super) fn resolve_names(ctx: &mut Context<'_>) { insert_name(file_id, top_id, top, namespace, ctx) } - let _ = std::mem::replace(ctx.names, names); + let _ = core::mem::replace(ctx.names, names); } fn insert_name( diff --git a/psl/parser-database/src/relations.rs b/psl/parser-database/src/relations.rs index 7a155c17e858..5be525f9eaa4 100644 --- a/psl/parser-database/src/relations.rs +++ b/psl/parser-database/src/relations.rs @@ -5,9 +5,9 @@ use crate::{ walkers::RelationFieldId, {context::Context, types::RelationField}, }; +use alloc::{collections::BTreeSet, fmt, vec::Vec}; use enumflags2::bitflags; -use rustc_hash::FxHashMap as HashMap; -use std::{collections::BTreeSet, fmt}; +use hashbrown::HashMap; /// Detect relation types and construct relation objects to the database. pub(super) fn infer_relations(ctx: &mut Context<'_>) { @@ -18,7 +18,7 @@ pub(super) fn infer_relations(ctx: &mut Context<'_>) { ingest_relation(evidence, &mut relations, ctx); } - let _ = std::mem::replace(ctx.relations, relations); + let _ = core::mem::replace(ctx.relations, relations); } /// Identifier for a single relation in a Prisma schema. @@ -82,7 +82,7 @@ pub(crate) struct Relations { back: BTreeSet<(crate::ModelId, crate::ModelId, RelationId)>, } -impl std::ops::Index for Relations { +impl core::ops::Index for Relations { type Output = Relation; fn index(&self, index: RelationId) -> &Self::Output { @@ -90,7 +90,7 @@ impl std::ops::Index for Relations { } } -impl std::ops::Index for Relations { +impl core::ops::Index for Relations { type Output = RelationId; fn index(&self, index: RelationFieldId) -> &Self::Output { diff --git a/psl/parser-database/src/types.rs b/psl/parser-database/src/types.rs index 2081e0337ec5..c83aa5fe2c65 100644 --- a/psl/parser-database/src/types.rs +++ b/psl/parser-database/src/types.rs @@ -1,11 +1,11 @@ pub(crate) mod index_fields; use crate::{DatamodelError, context::Context, interner::StringId, walkers::IndexFieldWalker}; +use alloc::{collections::BTreeMap, fmt, string::String, vec::Vec}; use either::Either; use enumflags2::bitflags; -use rustc_hash::FxHashMap as HashMap; +use hashbrown::HashMap; use schema_ast::ast::{self, EnumValueId, WithName}; -use std::{collections::BTreeMap, fmt}; pub(super) fn resolve_types(ctx: &mut Context<'_>) { for ((file_id, top_id), top) in ctx.iter_tops() { @@ -123,7 +123,7 @@ impl Types { } } -impl std::ops::Index for Types { +impl core::ops::Index for Types { type Output = RelationField; fn index(&self, index: RelationFieldId) -> &Self::Output { @@ -131,13 +131,13 @@ impl std::ops::Index for Types { } } -impl std::ops::IndexMut for Types { +impl core::ops::IndexMut for Types { fn index_mut(&mut self, index: RelationFieldId) -> &mut Self::Output { &mut self.relation_fields[index.0 as usize] } } -impl std::ops::Index for Types { +impl core::ops::Index for Types { type Output = ScalarField; fn index(&self, index: ScalarFieldId) -> &Self::Output { @@ -145,7 +145,7 @@ impl std::ops::Index for Types { } } -impl std::ops::IndexMut for Types { +impl core::ops::IndexMut for Types { fn index_mut(&mut self, index: ScalarFieldId) -> &mut Self::Output { &mut self.scalar_fields[index.0 as usize] } diff --git a/psl/parser-database/src/types/index_fields.rs b/psl/parser-database/src/types/index_fields.rs index f869bde4ecfc..ba239f926e40 100644 --- a/psl/parser-database/src/types/index_fields.rs +++ b/psl/parser-database/src/types/index_fields.rs @@ -1,3 +1,5 @@ +use alloc::{borrow::ToOwned, string::ToString, vec::Vec}; + use crate::{DatamodelError, ast, coerce, types::SortOrder}; pub(crate) enum OperatorClass<'a> { diff --git a/psl/parser-database/src/walkers/composite_type.rs b/psl/parser-database/src/walkers/composite_type.rs index 01143269228d..73754c817751 100644 --- a/psl/parser-database/src/walkers/composite_type.rs +++ b/psl/parser-database/src/walkers/composite_type.rs @@ -3,6 +3,7 @@ use crate::{ ast::{self, NewlineType, WithDocumentation, WithName, WithSpan}, walkers::{Walker, newline}, }; +use alloc::string::String; use diagnostics::Span; use super::EnumWalker; diff --git a/psl/parser-database/src/walkers/field.rs b/psl/parser-database/src/walkers/field.rs index 7b342735ea80..31fc984b093b 100644 --- a/psl/parser-database/src/walkers/field.rs +++ b/psl/parser-database/src/walkers/field.rs @@ -3,6 +3,7 @@ use crate::{ ScalarType, types::{RefinedFieldVariant, RelationField, ScalarField}, }; +use alloc::string::String; use schema_ast::ast; /// A model field, scalar or relation. diff --git a/psl/parser-database/src/walkers/index.rs b/psl/parser-database/src/walkers/index.rs index b62a9c4ddc83..3f728eda0173 100644 --- a/psl/parser-database/src/walkers/index.rs +++ b/psl/parser-database/src/walkers/index.rs @@ -1,3 +1,4 @@ +use alloc::string::String; use either::Either; use super::CompositeTypeFieldWalker; diff --git a/psl/parser-database/src/walkers/model.rs b/psl/parser-database/src/walkers/model.rs index 6fec1774f41d..b1d4c0fac761 100644 --- a/psl/parser-database/src/walkers/model.rs +++ b/psl/parser-database/src/walkers/model.rs @@ -2,6 +2,8 @@ mod primary_key; mod shard_key; mod unique_criteria; +use alloc::vec::Vec; + pub use primary_key::*; pub use shard_key::*; diff --git a/psl/parser-database/src/walkers/relation/implicit_many_to_many.rs b/psl/parser-database/src/walkers/relation/implicit_many_to_many.rs index f47f793e45ca..38f083e80ad5 100644 --- a/psl/parser-database/src/walkers/relation/implicit_many_to_many.rs +++ b/psl/parser-database/src/walkers/relation/implicit_many_to_many.rs @@ -1,4 +1,4 @@ -use std::fmt::Display; +use core::fmt::Display; use crate::{ relations::{ManyToManyRelationId, Relation, RelationAttributes}, @@ -84,7 +84,7 @@ impl<'db> ImplicitManyToManyRelationWalker<'db> { pub struct ImplicitManyToManyRelationTableName<'db>(RelationName<'db>); impl Display for ImplicitManyToManyRelationTableName<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.write_str("_")?; Display::fmt(&self.0, f) } diff --git a/psl/parser-database/src/walkers/relation/inline.rs b/psl/parser-database/src/walkers/relation/inline.rs index 022f5b5580cd..57f1368bd54b 100644 --- a/psl/parser-database/src/walkers/relation/inline.rs +++ b/psl/parser-database/src/walkers/relation/inline.rs @@ -1,5 +1,7 @@ mod complete; +use alloc::boxed::Box; + pub use complete::CompleteInlineRelationWalker; use super::RelationWalker; diff --git a/psl/parser-database/src/walkers/relation_field.rs b/psl/parser-database/src/walkers/relation_field.rs index fca0e5e711b5..ebd80a4d70b0 100644 --- a/psl/parser-database/src/walkers/relation_field.rs +++ b/psl/parser-database/src/walkers/relation_field.rs @@ -4,8 +4,8 @@ use crate::{ types::{RelationField, RelationFieldId}, walkers::*, }; -use std::{ - borrow::Cow, +use alloc::{borrow::Cow, string::String}; +use core::{ fmt::{self, Debug}, hash::Hasher, }; @@ -191,7 +191,7 @@ impl PartialEq for RelationName<'_> { impl Eq for RelationName<'_> {} impl Ord for RelationName<'_> { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { match (self, other) { (Self::Explicit(l0), Self::Explicit(r0)) => l0.cmp(r0), (Self::Generated(l0), Self::Generated(r0)) => l0.cmp(r0), @@ -202,12 +202,12 @@ impl Ord for RelationName<'_> { } impl PartialOrd for RelationName<'_> { - fn partial_cmp(&self, other: &Self) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } -impl std::hash::Hash for RelationName<'_> { +impl core::hash::Hash for RelationName<'_> { fn hash(&self, state: &mut H) { match self { RelationName::Explicit(s) => s.hash(state), diff --git a/psl/parser-database/src/walkers/scalar_field.rs b/psl/parser-database/src/walkers/scalar_field.rs index 3d2ef841eb51..5af1642a11bd 100644 --- a/psl/parser-database/src/walkers/scalar_field.rs +++ b/psl/parser-database/src/walkers/scalar_field.rs @@ -1,4 +1,4 @@ -use std::fmt; +use alloc::{fmt, string::String, vec::Vec}; use crate::{ OperatorClass, ParserDatabase, ScalarFieldId, ScalarFieldType, diff --git a/psl/psl-core/Cargo.toml b/psl/psl-core/Cargo.toml index 4195cb508cf9..cdb9d9d5be18 100644 --- a/psl/psl-core/Cargo.toml +++ b/psl/psl-core/Cargo.toml @@ -10,6 +10,7 @@ mysql = [] cockroachdb = ["postgresql"] mssql = [] mongodb = [] +std = ["dep:connection-string"] [dependencies] diagnostics.workspace = true @@ -19,7 +20,7 @@ schema-ast.workspace = true bigdecimal.workspace = true chrono.workspace = true -connection-string.workspace = true +connection-string = { workspace = true, optional = true } itertools.workspace = true regex.workspace = true serde.workspace = true @@ -28,6 +29,8 @@ enumflags2.workspace = true indoc.workspace = true either.workspace = true hex.workspace = true +hashbrown = { workspace = true, features = ["serde"] } +lazy-race.workspace = true # For the connector API. lsp-types.workspace = true diff --git a/psl/psl-core/src/builtin_connectors/cockroach_datamodel_connector.rs b/psl/psl-core/src/builtin_connectors/cockroach_datamodel_connector.rs index b82d4ececabf..825f755a3aec 100644 --- a/psl/psl-core/src/builtin_connectors/cockroach_datamodel_connector.rs +++ b/psl/psl-core/src/builtin_connectors/cockroach_datamodel_connector.rs @@ -1,6 +1,12 @@ mod native_types; mod validations; +use alloc::{ + borrow::{Cow, ToOwned}, + string::{String, ToString}, + vec::Vec, +}; + pub use native_types::CockroachType; use crate::{ @@ -19,7 +25,6 @@ use crate::{ use chrono::*; use enumflags2::BitFlags; use lsp_types::{CompletionItem, CompletionItemKind, CompletionList}; -use std::borrow::Cow; use super::completions; diff --git a/psl/psl-core/src/builtin_connectors/completions.rs b/psl/psl-core/src/builtin_connectors/completions.rs index a0b0a1132745..806c638ed700 100644 --- a/psl/psl-core/src/builtin_connectors/completions.rs +++ b/psl/psl-core/src/builtin_connectors/completions.rs @@ -1,5 +1,6 @@ #[cfg(feature = "postgresql")] pub(crate) fn extensions_completion(completion_list: &mut lsp_types::CompletionList) { + use alloc::borrow::ToOwned; use lsp_types::*; completion_list.items.push(CompletionItem { label: "extensions".to_owned(), @@ -20,6 +21,7 @@ pub(crate) fn extensions_completion(completion_list: &mut lsp_types::CompletionL #[cfg(any(feature = "postgresql", feature = "cockroachdb", feature = "mssql"))] pub(crate) fn schemas_completion(completion_list: &mut lsp_types::CompletionList) { + use alloc::borrow::ToOwned; use lsp_types::*; completion_list.items.push(CompletionItem { label: "schemas".to_owned(), diff --git a/psl/psl-core/src/builtin_connectors/mongodb.rs b/psl/psl-core/src/builtin_connectors/mongodb.rs index eadaa51f9077..80913596fb93 100644 --- a/psl/psl-core/src/builtin_connectors/mongodb.rs +++ b/psl/psl-core/src/builtin_connectors/mongodb.rs @@ -11,9 +11,10 @@ use crate::{ diagnostics::{Diagnostics, Span}, parser_database::{ReferentialAction, ScalarType, walkers::*}, }; +use alloc::{string::String, vec::Vec}; +use core::result::Result as StdResult; use enumflags2::BitFlags; use mongodb_types::*; -use std::result::Result as StdResult; const CAPABILITIES: ConnectorCapabilities = enumflags2::make_bitflags!(ConnectorCapability::{ Json | diff --git a/psl/psl-core/src/builtin_connectors/mongodb/mongodb_types.rs b/psl/psl-core/src/builtin_connectors/mongodb/mongodb_types.rs index bc4c19ca549c..8cad6c5c9dec 100644 --- a/psl/psl-core/src/builtin_connectors/mongodb/mongodb_types.rs +++ b/psl/psl-core/src/builtin_connectors/mongodb/mongodb_types.rs @@ -1,5 +1,6 @@ use crate::parser_database::ScalarType; -use std::{collections::HashMap, sync::LazyLock}; +use hashbrown::HashMap; +use lazy_race::LazyRace; crate::native_type_definition! { /// MongoDB native types. @@ -31,7 +32,7 @@ crate::native_type_definition! { // Regex } -static DEFAULT_MAPPING: LazyLock> = LazyLock::new(|| { +static DEFAULT_MAPPING: LazyRace> = LazyRace::new(|| { vec![ (ScalarType::Int, MongoDbType::Long), (ScalarType::BigInt, MongoDbType::Long), diff --git a/psl/psl-core/src/builtin_connectors/mssql_datamodel_connector.rs b/psl/psl-core/src/builtin_connectors/mssql_datamodel_connector.rs index 71ae01e0ef0f..3a60a1575c66 100644 --- a/psl/psl-core/src/builtin_connectors/mssql_datamodel_connector.rs +++ b/psl/psl-core/src/builtin_connectors/mssql_datamodel_connector.rs @@ -1,6 +1,12 @@ mod native_types; mod validations; +use alloc::{ + borrow::ToOwned, + string::{String, ToString}, + vec::Vec, +}; + pub use native_types::{MsSqlType, MsSqlTypeParameter}; use crate::{ diff --git a/psl/psl-core/src/builtin_connectors/mssql_datamodel_connector/native_types.rs b/psl/psl-core/src/builtin_connectors/mssql_datamodel_connector/native_types.rs index 5ef24a40464d..113ba1f65895 100644 --- a/psl/psl-core/src/builtin_connectors/mssql_datamodel_connector/native_types.rs +++ b/psl/psl-core/src/builtin_connectors/mssql_datamodel_connector/native_types.rs @@ -1,4 +1,8 @@ -use std::fmt; +use alloc::{ + fmt, + string::{String, ToString}, + vec::Vec, +}; #[derive(Debug, Clone, PartialEq, Copy)] pub enum MsSqlTypeParameter { diff --git a/psl/psl-core/src/builtin_connectors/mysql_datamodel_connector.rs b/psl/psl-core/src/builtin_connectors/mysql_datamodel_connector.rs index dc9c30702a68..ce40a0309896 100644 --- a/psl/psl-core/src/builtin_connectors/mysql_datamodel_connector.rs +++ b/psl/psl-core/src/builtin_connectors/mysql_datamodel_connector.rs @@ -1,6 +1,8 @@ mod native_types; mod validations; +use alloc::{borrow::ToOwned, string::String, vec::Vec}; + use chrono::FixedOffset; pub use native_types::MySqlType; use prisma_value::{PrismaValueResult, decode_bytes}; diff --git a/psl/psl-core/src/builtin_connectors/native_type_definition.rs b/psl/psl-core/src/builtin_connectors/native_type_definition.rs index c4e5d1df2007..8786a2c7c15e 100644 --- a/psl/psl-core/src/builtin_connectors/native_type_definition.rs +++ b/psl/psl-core/src/builtin_connectors/native_type_definition.rs @@ -37,7 +37,7 @@ macro_rules! native_type_definition { ); impl $enumName { - pub fn to_parts(&self) -> (&'static str, Vec) { + pub fn to_parts(&self) -> (&'static str, $crate::alloc::vec::Vec<$crate::alloc::string::String>) { use $enumName::*; $crate::native_type_definition!( @@ -51,7 +51,7 @@ macro_rules! native_type_definition { #[allow(unused_variables)] // some impls (mongo) don't use the arguments param pub fn from_parts( name: &str, - arguments: &[String], + arguments: &[$crate::alloc::string::String], span: $crate::parser_database::ast::Span, diagnostics: &mut $crate::diagnostics::Diagnostics ) -> Option { @@ -148,7 +148,7 @@ macro_rules! native_type_definition { $self, { $($body)* - $variant => (stringify!($variant), Vec::new()), + $variant => (stringify!($variant), $crate::alloc::vec::Vec::new()), } $($tail)* } diff --git a/psl/psl-core/src/builtin_connectors/postgres_datamodel_connector.rs b/psl/psl-core/src/builtin_connectors/postgres_datamodel_connector.rs index 398a542086c0..5dfbcba7e99a 100644 --- a/psl/psl-core/src/builtin_connectors/postgres_datamodel_connector.rs +++ b/psl/psl-core/src/builtin_connectors/postgres_datamodel_connector.rs @@ -2,6 +2,13 @@ mod datasource; mod native_types; mod validations; +use alloc::{ + borrow::{Cow, ToOwned}, + boxed::Box, + string::{String, ToString}, + vec::Vec, +}; + pub use native_types::PostgresType; use crate::{ @@ -16,8 +23,8 @@ use crate::{ use PostgresType::*; use chrono::*; use enumflags2::BitFlags; +use hashbrown::HashMap; use lsp_types::{CompletionItem, CompletionItemKind, CompletionList, InsertTextFormat}; -use std::{borrow::Cow, collections::HashMap}; use super::completions; diff --git a/psl/psl-core/src/builtin_connectors/postgres_datamodel_connector/datasource.rs b/psl/psl-core/src/builtin_connectors/postgres_datamodel_connector/datasource.rs index b208548d5d6c..02e62d0357ab 100644 --- a/psl/psl-core/src/builtin_connectors/postgres_datamodel_connector/datasource.rs +++ b/psl/psl-core/src/builtin_connectors/postgres_datamodel_connector/datasource.rs @@ -4,7 +4,11 @@ use crate::{ diagnostics::{DatamodelError, Diagnostics}, parser_database::{ast, coerce, coerce_array}, }; -use std::collections::{HashMap, HashSet}; +use alloc::{ + string::{String, ToString}, + vec::Vec, +}; +use hashbrown::{HashMap, HashSet}; pub(super) fn parse_extensions( args: &mut HashMap<&str, (ast::Span, &ast::Expression)>, diff --git a/psl/psl-core/src/builtin_connectors/sqlite_datamodel_connector.rs b/psl/psl-core/src/builtin_connectors/sqlite_datamodel_connector.rs index 0393513858e9..73cf70a16016 100644 --- a/psl/psl-core/src/builtin_connectors/sqlite_datamodel_connector.rs +++ b/psl/psl-core/src/builtin_connectors/sqlite_datamodel_connector.rs @@ -6,6 +6,11 @@ use crate::{ diagnostics::{DatamodelError, Diagnostics, Span}, parser_database::{ReferentialAction, ScalarType}, }; +use alloc::{ + borrow::ToOwned, + string::{String, ToString}, + vec::Vec, +}; use enumflags2::BitFlags; const NATIVE_TYPE_CONSTRUCTORS: &[NativeTypeConstructor] = &[]; diff --git a/psl/psl-core/src/builtin_connectors/utils.rs b/psl/psl-core/src/builtin_connectors/utils.rs index ee2b4abb85c7..d8bd7eb8502e 100644 --- a/psl/psl-core/src/builtin_connectors/utils.rs +++ b/psl/psl-core/src/builtin_connectors/utils.rs @@ -28,6 +28,7 @@ pub(crate) mod common { #[cfg(feature = "postgresql")] pub(crate) mod postgres { + use alloc::vec::Vec; use chrono::*; pub(crate) fn parse_timestamptz(str: &str) -> Result, chrono::ParseError> { diff --git a/psl/psl-core/src/common/preview_features.rs b/psl/psl-core/src/common/preview_features.rs index 6e0baa6a1bd9..e6bb9b428c12 100644 --- a/psl/psl-core/src/common/preview_features.rs +++ b/psl/psl-core/src/common/preview_features.rs @@ -1,7 +1,7 @@ +use alloc::{fmt, string::ToString}; +use hashbrown::HashMap; +use lazy_race::LazyRace; use serde::{Serialize, Serializer}; -use std::collections::HashMap; -use std::fmt; -use std::sync::LazyLock; /// A set of preview features. pub type PreviewFeatures = enumflags2::BitFlags; @@ -148,8 +148,8 @@ pub struct FeatureMapWithProvider<'a> { /// The default feature map with an unknown provider. /// This is used for convenience in `prisma/language-tools`, which needs the list of all available preview features /// before a provider is necessarily known. -pub static ALL_PREVIEW_FEATURES: LazyLock> = - LazyLock::new(|| FeatureMapWithProvider::new(None)); +pub static ALL_PREVIEW_FEATURES: LazyRace> = + LazyRace::new(|| FeatureMapWithProvider::new(None)); impl<'a> FeatureMapWithProvider<'a> { pub fn new(connector_provider: Option<&'a str>) -> FeatureMapWithProvider<'a> { diff --git a/psl/psl-core/src/configuration/configuration_struct.rs b/psl/psl-core/src/configuration/configuration_struct.rs index 2ffcb7f919ed..9f55ba94a3f1 100644 --- a/psl/psl-core/src/configuration/configuration_struct.rs +++ b/psl/psl-core/src/configuration/configuration_struct.rs @@ -4,6 +4,7 @@ use crate::{ datamodel_connector::RelationMode, diagnostics::{DatamodelError, Diagnostics}, }; +use alloc::{string::String, vec::Vec}; use enumflags2::BitFlags; #[derive(Debug, Default)] diff --git a/psl/psl-core/src/configuration/datasource.rs b/psl/psl-core/src/configuration/datasource.rs index 8bafb385a35c..51f47c09c30d 100644 --- a/psl/psl-core/src/configuration/datasource.rs +++ b/psl/psl-core/src/configuration/datasource.rs @@ -1,12 +1,15 @@ +use alloc::{borrow::Cow, boxed::Box, string::String, vec::Vec}; +use core::any::Any; + use schema_ast::ast::WithSpan; +#[cfg(feature = "std")] +use crate::set_config_dir; use crate::{ configuration::StringFromEnvVar, datamodel_connector::{Connector, ConnectorCapabilities, RelationMode}, diagnostics::{DatamodelError, Diagnostics, Span}, - set_config_dir, }; -use std::{any::Any, borrow::Cow, path::Path}; /// a `datasource` from the prisma schema. pub struct Datasource { @@ -57,8 +60,8 @@ impl DatasourceConnectorData { } } -impl std::fmt::Debug for Datasource { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Datasource { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("Datasource") .field("name", &self.name) .field("provider", &self.provider) @@ -207,7 +210,8 @@ impl Datasource { /// context of Node-API integration. /// /// P.S. Don't forget to add new parameters here if needed! - pub fn load_url_with_config_dir(&self, config_dir: &Path, env: F) -> Result + #[cfg(feature = "std")] + pub fn load_url_with_config_dir(&self, config_dir: &std::path::Path, env: F) -> Result where F: Fn(&str) -> Option, { @@ -219,6 +223,7 @@ impl Datasource { } /// Load the shadow database URL, validating it and resolving env vars in the process. + #[cfg(feature = "std")] pub fn load_shadow_database_url(&self) -> Result, Diagnostics> { let (url, url_span) = match self .shadow_database_url diff --git a/psl/psl-core/src/configuration/env_vars.rs b/psl/psl-core/src/configuration/env_vars.rs index fe6c269a38e1..3725ab9bd5c6 100644 --- a/psl/psl-core/src/configuration/env_vars.rs +++ b/psl/psl-core/src/configuration/env_vars.rs @@ -1,3 +1,8 @@ +use alloc::{ + borrow::ToOwned, + string::{String, ToString}, +}; + use crate::parser_database::{ast, coerce}; use diagnostics::{DatamodelError, DatamodelWarning, Diagnostics}; use schema_ast::ast::WithSpan; diff --git a/psl/psl-core/src/configuration/generator.rs b/psl/psl-core/src/configuration/generator.rs index 2b6b9098fd97..fc4b380b7365 100644 --- a/psl/psl-core/src/configuration/generator.rs +++ b/psl/psl-core/src/configuration/generator.rs @@ -1,13 +1,19 @@ +use alloc::{ + borrow::ToOwned, + string::{String, ToString}, + vec::Vec, +}; + use crate::{ PreviewFeature, configuration::{EnvFunction, StringFromEnvVar}, }; use diagnostics::{Diagnostics, Span}; use enumflags2::BitFlags; +use hashbrown::HashMap; use parser_database::ast::Expression; use schema_ast::ast::WithSpan; use serde::{Serialize, Serializer, ser::SerializeSeq}; -use std::collections::HashMap; #[derive(Debug, Serialize, Clone)] #[serde(untagged)] diff --git a/psl/psl-core/src/datamodel_connector.rs b/psl/psl-core/src/datamodel_connector.rs index d3cc3c7a7a8f..da9da2653c63 100644 --- a/psl/psl-core/src/datamodel_connector.rs +++ b/psl/psl-core/src/datamodel_connector.rs @@ -15,6 +15,12 @@ mod filters; mod native_types; mod relation_mode; +use alloc::{ + borrow::{Cow, ToOwned}, + string::String, + vec::Vec, +}; + pub use self::{ capabilities::{ConnectorCapabilities, ConnectorCapability}, completions::format_completion_docs, @@ -28,13 +34,13 @@ use crate::{Configuration, Datasource, PreviewFeature, configuration::Datasource use chrono::{DateTime, FixedOffset}; use diagnostics::{DatamodelError, Diagnostics, NativeTypeErrorFactory, Span}; use enumflags2::BitFlags; +use hashbrown::HashMap; use lsp_types::CompletionList; use parser_database::{ IndexAlgorithm, ParserDatabase, ReferentialAction, ScalarType, ast::{self, SchemaPosition}, walkers, }; -use std::{borrow::Cow, collections::HashMap}; pub const EXTENSIONS_KEY: &str = "extensions"; diff --git a/psl/psl-core/src/datamodel_connector/capabilities.rs b/psl/psl-core/src/datamodel_connector/capabilities.rs index 744966fb05ca..7c966b02ba7a 100644 --- a/psl/psl-core/src/datamodel_connector/capabilities.rs +++ b/psl/psl-core/src/datamodel_connector/capabilities.rs @@ -1,4 +1,5 @@ -use std::{fmt, str::FromStr}; +use alloc::string::String; +use core::{fmt, str::FromStr}; /// Not all Databases are created equal. Hence connectors for our datasources support different capabilities. /// These are used during schema validation. E.g. if a connector does not support enums an error will be raised. diff --git a/psl/psl-core/src/datamodel_connector/completions.rs b/psl/psl-core/src/datamodel_connector/completions.rs index 08721917c41d..07cf49d8cd8b 100644 --- a/psl/psl-core/src/datamodel_connector/completions.rs +++ b/psl/psl-core/src/datamodel_connector/completions.rs @@ -1,4 +1,5 @@ -use std::collections::HashMap; +use alloc::{string::String, vec::Vec}; +use hashbrown::HashMap; /// Formats the documentation for a completion. /// example: How the completion is expected to be used. diff --git a/psl/psl-core/src/datamodel_connector/constraint_names.rs b/psl/psl-core/src/datamodel_connector/constraint_names.rs index adf0cb083aaf..3d6408d2b076 100644 --- a/psl/psl-core/src/datamodel_connector/constraint_names.rs +++ b/psl/psl-core/src/datamodel_connector/constraint_names.rs @@ -1,4 +1,5 @@ use crate::datamodel_connector::Connector; +use alloc::string::String; use diagnostics::{DatamodelError, Span}; pub struct ConstraintNames; @@ -143,7 +144,7 @@ impl ConstraintNames { /// This method can help you to truncate a string so that it's still /// valid UTF-8, but doesn't exceed a given number of bytes. /// -/// To be replaced with `std::str::floor_char_boundary` when it's +/// To be replaced with `core::str::floor_char_boundary` when it's /// stabilized. fn floor_char_boundary(s: &str, mut index: usize) -> usize { if index >= s.len() { diff --git a/psl/psl-core/src/datamodel_connector/empty_connector.rs b/psl/psl-core/src/datamodel_connector/empty_connector.rs index f9e0fcfcfd6a..5fbb6642ae92 100644 --- a/psl/psl-core/src/datamodel_connector/empty_connector.rs +++ b/psl/psl-core/src/datamodel_connector/empty_connector.rs @@ -1,4 +1,5 @@ pub(crate) use crate::datamodel_connector::*; +use alloc::{string::String, vec::Vec}; use diagnostics::{DatamodelError, Span}; use enumflags2::BitFlags; @@ -12,7 +13,7 @@ impl Connector for EmptyDatamodelConnector { } fn name(&self) -> &str { - std::any::type_name::() + core::any::type_name::() } fn foreign_key_referential_actions(&self) -> BitFlags { diff --git a/psl/psl-core/src/datamodel_connector/filters.rs b/psl/psl-core/src/datamodel_connector/filters.rs index feeac90ecdda..41f4c621a477 100644 --- a/psl/psl-core/src/datamodel_connector/filters.rs +++ b/psl/psl-core/src/datamodel_connector/filters.rs @@ -2,6 +2,8 @@ #![deny(missing_docs)] +use alloc::{borrow::ToOwned, string::String}; + use enumflags2::*; macro_rules! filters { diff --git a/psl/psl-core/src/datamodel_connector/native_types.rs b/psl/psl-core/src/datamodel_connector/native_types.rs index 57a9552244fd..004260f41451 100644 --- a/psl/psl-core/src/datamodel_connector/native_types.rs +++ b/psl/psl-core/src/datamodel_connector/native_types.rs @@ -1,5 +1,10 @@ use crate::datamodel_connector::ScalarType; -use std::{any::Any, sync::Arc}; +use alloc::{ + string::{String, ToString}, + sync::Arc, + vec::Vec, +}; +use core::any::Any; /// Represents an available native type. pub struct NativeTypeConstructor { @@ -19,8 +24,8 @@ pub struct NativeTypeConstructor { #[derive(Clone)] pub struct NativeTypeInstance(Arc); -impl std::fmt::Debug for NativeTypeInstance { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for NativeTypeInstance { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.write_str("NativeTypeInstance(..)") } } diff --git a/psl/psl-core/src/datamodel_connector/relation_mode.rs b/psl/psl-core/src/datamodel_connector/relation_mode.rs index 3ab3db4c67c6..4a9a8c43eb55 100644 --- a/psl/psl-core/src/datamodel_connector/relation_mode.rs +++ b/psl/psl-core/src/datamodel_connector/relation_mode.rs @@ -1,6 +1,6 @@ use crate::datamodel_connector::ReferentialAction; +use core::fmt; use enumflags2::{BitFlags, bitflags}; -use std::fmt; /// Defines the part of the stack where referential actions are handled. #[bitflags] diff --git a/psl/psl-core/src/datamodel_connector/walker_ext_traits.rs b/psl/psl-core/src/datamodel_connector/walker_ext_traits.rs index ec2be2c131cd..d0a3f2c16e47 100644 --- a/psl/psl-core/src/datamodel_connector/walker_ext_traits.rs +++ b/psl/psl-core/src/datamodel_connector/walker_ext_traits.rs @@ -4,11 +4,11 @@ use crate::{ Connector, NativeTypeInstance, ReferentialAction, RelationMode, constraint_names::ConstraintNames, }, }; +use alloc::{borrow::Cow, vec::Vec}; use parser_database::{ ast::{self, WithSpan}, walkers::*, }; -use std::borrow::Cow; use super::ConnectorCapability; diff --git a/psl/psl-core/src/lib.rs b/psl/psl-core/src/lib.rs index 065418232fa2..b606407eafba 100644 --- a/psl/psl-core/src/lib.rs +++ b/psl/psl-core/src/lib.rs @@ -1,6 +1,10 @@ #![doc = include_str!("../README.md")] #![deny(rust_2018_idioms, unsafe_code)] #![allow(clippy::derive_partial_eq_without_eq)] +#![cfg_attr(not(feature = "std"), no_std)] + +#[cfg_attr(not(feature = "std"), macro_use)] +extern crate alloc; pub mod builtin_connectors; pub mod datamodel_connector; @@ -12,10 +16,15 @@ pub mod mcf; mod common; mod configuration; mod reformat; +#[cfg(feature = "std")] mod set_config_dir; mod validate; -use std::sync::Arc; +use alloc::{ + borrow::ToOwned, + string::{String, ToString}, + sync::Arc, +}; pub use crate::{ common::{ALL_PREVIEW_FEATURES, FeatureMapWithProvider, PreviewFeature, PreviewFeatures}, @@ -27,6 +36,7 @@ pub use crate::{ pub use diagnostics; pub use parser_database::{self, coerce, coerce_array, generators, is_reserved_type_name}; pub use schema_ast; +#[cfg(feature = "std")] pub use set_config_dir::set_config_dir; use self::validate::{datasource_loader, generator_loader}; @@ -45,8 +55,8 @@ pub struct ValidatedSchema { relation_mode: datamodel_connector::RelationMode, } -impl std::fmt::Debug for ValidatedSchema { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for ValidatedSchema { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.write_str("") } } diff --git a/psl/psl-core/src/mcf.rs b/psl/psl-core/src/mcf.rs index 75cde3bb5f01..b7ab1c97b4f0 100644 --- a/psl/psl-core/src/mcf.rs +++ b/psl/psl-core/src/mcf.rs @@ -1,6 +1,8 @@ mod generator; mod source; +use alloc::{borrow::ToOwned, string::String, vec::Vec}; + pub use generator::*; use parser_database::Files; pub use source::*; diff --git a/psl/psl-core/src/mcf/generator.rs b/psl/psl-core/src/mcf/generator.rs index 2537e304c9df..df9c17cebe95 100644 --- a/psl/psl-core/src/mcf/generator.rs +++ b/psl/psl-core/src/mcf/generator.rs @@ -1,3 +1,5 @@ +use alloc::string::String; + use itertools::Itertools; use parser_database::Files; use serde::Serialize; diff --git a/psl/psl-core/src/mcf/source.rs b/psl/psl-core/src/mcf/source.rs index 068627828b3f..4a73f2e77e8b 100644 --- a/psl/psl-core/src/mcf/source.rs +++ b/psl/psl-core/src/mcf/source.rs @@ -1,3 +1,8 @@ +use alloc::{ + string::{String, ToString}, + vec::Vec, +}; + use parser_database::Files; use schema_ast::ast::WithSpan; diff --git a/psl/psl-core/src/reformat.rs b/psl/psl-core/src/reformat.rs index a12a09d3c66e..f0770e950108 100644 --- a/psl/psl-core/src/reformat.rs +++ b/psl/psl-core/src/reformat.rs @@ -1,8 +1,14 @@ +use alloc::{ + borrow::{Cow, ToOwned}, + string::String, + vec::Vec, +}; + use crate::{ParserDatabase, ValidatedSchema}; use diagnostics::FileId; +use hashbrown::HashMap; use parser_database::{ast::WithSpan, walkers}; use schema_ast::{SourceFile, ast}; -use std::{borrow::Cow, collections::HashMap}; /// Returns either the reformatted schema, or the original input if we can't reformat. This happens /// if and only if the source does not parse to a well formed AST. diff --git a/psl/psl-core/src/validate/datasource_loader.rs b/psl/psl-core/src/validate/datasource_loader.rs index 07d451dff4bb..d770fde57853 100644 --- a/psl/psl-core/src/validate/datasource_loader.rs +++ b/psl/psl-core/src/validate/datasource_loader.rs @@ -1,3 +1,9 @@ +use alloc::{ + borrow::{Cow, ToOwned}, + string::String, + vec::Vec, +}; + use crate::{ Datasource, ast::{self, SourceConfig, Span, WithName}, @@ -6,12 +12,12 @@ use crate::{ diagnostics::{DatamodelError, Diagnostics}, }; use diagnostics::DatamodelWarning; +use hashbrown::HashMap; use parser_database::{ ast::{Expression, WithDocumentation}, coerce, coerce_array, coerce_opt, }; use schema_ast::ast::WithSpan; -use std::{borrow::Cow, collections::HashMap}; const PREVIEW_FEATURES_KEY: &str = "previewFeatures"; const SCHEMAS_KEY: &str = "schemas"; diff --git a/psl/psl-core/src/validate/generator_loader.rs b/psl/psl-core/src/validate/generator_loader.rs index 45dfdaeb3915..9ba809089627 100644 --- a/psl/psl-core/src/validate/generator_loader.rs +++ b/psl/psl-core/src/validate/generator_loader.rs @@ -4,14 +4,19 @@ use crate::{ configuration::{Generator, GeneratorConfigValue, StringFromEnvVar}, diagnostics::*, }; +use alloc::{ + borrow::ToOwned, + string::{String, ToString}, + vec::Vec, +}; use enumflags2::BitFlags; +use hashbrown::HashMap; use itertools::Itertools; use parser_database::{ ast::{self, WithDocumentation}, coerce, coerce_array, }; use schema_ast::ast::WithName; -use std::collections::HashMap; const PROVIDER_KEY: &str = "provider"; const OUTPUT_KEY: &str = "output"; diff --git a/psl/psl-core/src/validate/validation_pipeline/validations/composite_types.rs b/psl/psl-core/src/validate/validation_pipeline/validations/composite_types.rs index 287093ec399d..424c92e7f1c4 100644 --- a/psl/psl-core/src/validate/validation_pipeline/validations/composite_types.rs +++ b/psl/psl-core/src/validate/validation_pipeline/validations/composite_types.rs @@ -1,12 +1,12 @@ use super::default_value; use crate::{datamodel_connector::ConnectorCapability, validate::validation_pipeline::context::Context}; +use alloc::{fmt, rc::Rc, vec::Vec}; use diagnostics::DatamodelError; use parser_database::{ ScalarFieldType, ast::WithSpan, walkers::{CompositeTypeFieldWalker, CompositeTypeWalker}, }; -use std::{fmt, rc::Rc}; /// Detect compound type chains that form a cycle, that is not broken with either an optional or an /// array type. diff --git a/psl/psl-core/src/validate/validation_pipeline/validations/constraint_namespace.rs b/psl/psl-core/src/validate/validation_pipeline/validations/constraint_namespace.rs index f4d42ec1e25f..1d689702fce3 100644 --- a/psl/psl-core/src/validate/validation_pipeline/validations/constraint_namespace.rs +++ b/psl/psl-core/src/validate/validation_pipeline/validations/constraint_namespace.rs @@ -1,5 +1,7 @@ use crate::datamodel_connector::{ConstraintScope, walker_ext_traits::*}; -use std::{borrow::Cow, collections::HashMap, ops::Deref}; +use alloc::{borrow::Cow, string::ToString}; +use core::ops::Deref; +use hashbrown::HashMap; /// A constraint namespace consists of two kinds of namespaces: /// diff --git a/psl/psl-core/src/validate/validation_pipeline/validations/enums.rs b/psl/psl-core/src/validate/validation_pipeline/validations/enums.rs index 9ab356b0dfb4..df1641203d8c 100644 --- a/psl/psl-core/src/validate/validation_pipeline/validations/enums.rs +++ b/psl/psl-core/src/validate/validation_pipeline/validations/enums.rs @@ -4,7 +4,7 @@ use crate::{ parser_database::{ast::WithSpan, walkers::EnumWalker}, validate::validation_pipeline::context::Context, }; -use std::collections::HashSet; +use hashbrown::HashSet; pub(super) fn database_name_clashes(ctx: &mut Context<'_>) { let mut database_names: HashSet<(Option<&str>, &str)> = HashSet::with_capacity(ctx.db.enums_count()); diff --git a/psl/psl-core/src/validate/validation_pipeline/validations/fields.rs b/psl/psl-core/src/validate/validation_pipeline/validations/fields.rs index e6337bce7a3a..d712eff80cba 100644 --- a/psl/psl-core/src/validate/validation_pipeline/validations/fields.rs +++ b/psl/psl-core/src/validate/validation_pipeline/validations/fields.rs @@ -1,5 +1,3 @@ -use std::sync::LazyLock; - use super::{ constraint_namespace::ConstraintName, database_name::validate_db_name, @@ -8,6 +6,8 @@ use super::{ }; use crate::datamodel_connector::{ConnectorCapability, walker_ext_traits::*}; use crate::{diagnostics::DatamodelError, validate::validation_pipeline::context::Context}; +use alloc::{string::ToString, vec::Vec}; +use lazy_race::LazyRace; use parser_database::{ ScalarFieldType, ScalarType, ast::{self, WithSpan}, @@ -322,7 +322,7 @@ pub(super) fn validate_unsupported_field_type(field: ScalarFieldWalker<'_>, ctx: let source = if let Some(s) = ctx.datasource { s } else { return }; - static TYPE_REGEX: LazyLock = LazyLock::new(|| { + static TYPE_REGEX: LazyRace = LazyRace::new(|| { Regex::new(r"(?x) ^ # beginning of the string (?P[^(]+) # a required prefix that is any character until the first opening brace diff --git a/psl/psl-core/src/validate/validation_pipeline/validations/models.rs b/psl/psl-core/src/validate/validation_pipeline/validations/models.rs index f1055ffeec23..c9ff37172976 100644 --- a/psl/psl-core/src/validate/validation_pipeline/validations/models.rs +++ b/psl/psl-core/src/validate/validation_pipeline/validations/models.rs @@ -6,8 +6,9 @@ use crate::{ parser_database::ast::{WithName, WithSpan}, validate::validation_pipeline::context::Context, }; +use alloc::{borrow::Cow, vec::Vec}; +use hashbrown::HashMap; use parser_database::walkers::{ModelWalker, PrimaryKeyWalker}; -use std::{borrow::Cow, collections::HashMap}; /// A model must have either a primary key, or a unique criterion /// with no optional, commented-out or unsupported fields. diff --git a/psl/psl-core/src/validate/validation_pipeline/validations/names.rs b/psl/psl-core/src/validate/validation_pipeline/validations/names.rs index 93e4881765b8..5b36899d0f7f 100644 --- a/psl/psl-core/src/validate/validation_pipeline/validations/names.rs +++ b/psl/psl-core/src/validate/validation_pipeline/validations/names.rs @@ -1,9 +1,10 @@ use super::constraint_namespace::ConstraintNamespace; +use alloc::vec::Vec; +use hashbrown::{HashMap, HashSet}; use parser_database::{ ModelId, walkers::{RelationFieldId, RelationName}, }; -use std::collections::{HashMap, HashSet}; type RelationIdentifier<'db> = (ModelId, ModelId, RelationName<'db>); diff --git a/psl/psl-core/src/validate/validation_pipeline/validations/relation_fields.rs b/psl/psl-core/src/validate/validation_pipeline/validations/relation_fields.rs index 0fc681a6280e..ab9a94199563 100644 --- a/psl/psl-core/src/validate/validation_pipeline/validations/relation_fields.rs +++ b/psl/psl-core/src/validate/validation_pipeline/validations/relation_fields.rs @@ -5,6 +5,7 @@ use crate::{ diagnostics::DatamodelError, validate::validation_pipeline::context::Context, }; +use alloc::{fmt, string::String}; use diagnostics::DatamodelWarning; use enumflags2::BitFlags; use itertools::Itertools; @@ -12,7 +13,6 @@ use parser_database::{ ReferentialAction, walkers::{ModelWalker, RelationFieldId, RelationFieldWalker, RelationName}, }; -use std::fmt; struct Fields<'db> { fields: &'db [RelationFieldId], diff --git a/psl/psl-core/src/validate/validation_pipeline/validations/relations.rs b/psl/psl-core/src/validate/validation_pipeline/validations/relations.rs index 952ead899225..b3892602bc8c 100644 --- a/psl/psl-core/src/validate/validation_pipeline/validations/relations.rs +++ b/psl/psl-core/src/validate/validation_pipeline/validations/relations.rs @@ -7,7 +7,9 @@ mod visited_relation; use super::constraint_namespace::ConstraintName; use crate::datamodel_connector::{Connector, ConnectorCapability, RelationMode, walker_ext_traits::*}; use crate::{diagnostics::DatamodelError, validate::validation_pipeline::context::Context}; +use alloc::{collections::BTreeSet, rc::Rc, string::ToString, vec::Vec}; use diagnostics::DatamodelWarning; +use hashbrown::{HashMap, HashSet}; use indoc::formatdoc; use itertools::Itertools; use parser_database::ReferentialAction; @@ -17,10 +19,6 @@ use parser_database::{ ast::WithSpan, walkers::{CompleteInlineRelationWalker, InlineRelationWalker}, }; -use std::{ - collections::{BTreeSet, HashMap, HashSet}, - rc::Rc, -}; use visited_relation::*; const PRISMA_FORMAT_HINT: &str = "You can run `prisma format` to fix this automatically."; diff --git a/psl/psl-core/src/validate/validation_pipeline/validations/relations/many_to_many/implicit.rs b/psl/psl-core/src/validate/validation_pipeline/validations/relations/many_to_many/implicit.rs index 0aed29caec21..641a14a9a2ce 100644 --- a/psl/psl-core/src/validate/validation_pipeline/validations/relations/many_to_many/implicit.rs +++ b/psl/psl-core/src/validate/validation_pipeline/validations/relations/many_to_many/implicit.rs @@ -1,5 +1,6 @@ use crate::validate::validation_pipeline::{context::Context, validations::relations::RELATION_ATTRIBUTE_NAME}; use crate::{datamodel_connector::ConnectorCapability, diagnostics::DatamodelError}; +use alloc::vec::Vec; use parser_database::{ast::WithSpan, walkers::ImplicitManyToManyRelationWalker}; /// Our weird many-to-many requirement. diff --git a/psl/psl-core/src/validate/validation_pipeline/validations/relations/one_to_one.rs b/psl/psl-core/src/validate/validation_pipeline/validations/relations/one_to_one.rs index cfb8e2d2c3c4..f668fd0f9ab4 100644 --- a/psl/psl-core/src/validate/validation_pipeline/validations/relations/one_to_one.rs +++ b/psl/psl-core/src/validate/validation_pipeline/validations/relations/one_to_one.rs @@ -1,5 +1,6 @@ use super::*; use crate::{diagnostics::DatamodelError, validate::validation_pipeline::context::Context}; +use alloc::vec::Vec; use parser_database::ast::WithSpan; /// A relation should have the explicit and back-relation side defined. diff --git a/psl/psl-core/src/validate/validation_pipeline/validations/relations/visited_relation.rs b/psl/psl-core/src/validate/validation_pipeline/validations/relations/visited_relation.rs index 06891a8698d1..d377589ebf15 100644 --- a/psl/psl-core/src/validate/validation_pipeline/validations/relations/visited_relation.rs +++ b/psl/psl-core/src/validate/validation_pipeline/validations/relations/visited_relation.rs @@ -1,6 +1,6 @@ +use alloc::{fmt, rc::Rc, vec::Vec}; use itertools::Itertools; use parser_database::walkers::CompleteInlineRelationWalker; -use std::{fmt, rc::Rc}; /// A linked list structure for visited relation paths. #[derive(Clone)] diff --git a/psl/psl/Cargo.toml b/psl/psl/Cargo.toml index d61422ddef12..d78099d8ce32 100644 --- a/psl/psl/Cargo.toml +++ b/psl/psl/Cargo.toml @@ -11,11 +11,13 @@ cockroachdb = ["psl-core/cockroachdb", "postgresql"] mssql = ["psl-core/mssql"] mongodb = ["psl-core/mongodb"] all = ["postgresql", "sqlite", "mysql", "cockroachdb", "mssql", "mongodb"] +std = ["psl-core/std"] [dependencies] psl-core.workspace = true [dev-dependencies] +psl-core = { workspace = true, features = ["std"] } base64.workspace = true dissimilar.workspace = true expect-test.workspace = true diff --git a/psl/psl/README.md b/psl/psl/README.md index 90cb49b0409e..9a3f9a87be1e 100644 --- a/psl/psl/README.md +++ b/psl/psl/README.md @@ -17,6 +17,6 @@ Please see [`lib.rs`](src/lib.rs) and the [rustdoc documentation](https://prisma Main use-case, parsing a string to datamodel: ```ignore -let file = std::fs::read_to_string(&args[1]).unwrap(); +let file = core::fs::read_to_string(&args[1]).unwrap(); let validated_schema = datamodel::parse_schema(&file)?; ``` diff --git a/psl/psl/src/lib.rs b/psl/psl/src/lib.rs index 783efb7d80a8..824f4712cee4 100644 --- a/psl/psl/src/lib.rs +++ b/psl/psl/src/lib.rs @@ -1,8 +1,15 @@ #![doc = include_str!("../README.md")] #![deny(rust_2018_idioms, unsafe_code, missing_docs)] +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; + +use alloc::string::String; pub use psl_core::builtin_connectors; use psl_core::parser_database::Files; +#[cfg(any(feature = "std", test))] +pub use psl_core::set_config_dir; pub use psl_core::{ ALL_PREVIEW_FEATURES, Configuration, @@ -29,7 +36,6 @@ pub use psl_core::{ reformat_multiple, reformat_validated_schema_into_single, schema_ast, - set_config_dir, }; /// The implementation of the CLI getConfig() utility and its JSON format. diff --git a/psl/psl/tests/config/sources.rs b/psl/psl/tests/config/sources.rs index 8fc9b9dc3a37..6ef4c94cee6e 100644 --- a/psl/psl/tests/config/sources.rs +++ b/psl/psl/tests/config/sources.rs @@ -669,7 +669,7 @@ fn fail_when_no_source_is_declared() { --> schema.prisma:1  |   |  -  1 |  +  1 |   | ^ Unexpected token.  |  "#]]; diff --git a/psl/psl/tests/validation_tests.rs b/psl/psl/tests/validation_tests.rs index 9859dbbc6bd3..3b6c73a0a6fd 100644 --- a/psl/psl/tests/validation_tests.rs +++ b/psl/psl/tests/validation_tests.rs @@ -15,7 +15,7 @@ fn parse_schema_fail_on_diagnostics(file: impl Into) -> Result Ok(schema), (warnings, errors) => { - let mut message: Vec = Vec::new(); + let mut message = String::new(); for warn in warnings { warn.pretty_print(&mut message, file_name, datamodel_string) @@ -27,7 +27,7 @@ fn parse_schema_fail_on_diagnostics(file: impl Into) -> Result for SchemaAst { +impl core::ops::Index for SchemaAst { type Output = Model; fn index(&self, index: ModelId) -> &Self::Output { @@ -95,7 +96,7 @@ impl std::ops::Index for SchemaAst { #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct EnumId(u32); -impl std::ops::Index for SchemaAst { +impl core::ops::Index for SchemaAst { type Output = Enum; fn index(&self, index: EnumId) -> &Self::Output { @@ -107,7 +108,7 @@ impl std::ops::Index for SchemaAst { #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct GeneratorId(u32); -impl std::ops::Index for SchemaAst { +impl core::ops::Index for SchemaAst { type Output = GeneratorConfig; fn index(&self, index: GeneratorId) -> &Self::Output { @@ -119,7 +120,7 @@ impl std::ops::Index for SchemaAst { #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct SourceId(u32); -impl std::ops::Index for SchemaAst { +impl core::ops::Index for SchemaAst { type Output = SourceConfig; fn index(&self, index: SourceId) -> &Self::Output { @@ -169,7 +170,7 @@ impl TopId { } } -impl std::ops::Index for SchemaAst { +impl core::ops::Index for SchemaAst { type Output = Top; fn index(&self, index: TopId) -> &Self::Output { diff --git a/psl/schema-ast/src/ast/argument.rs b/psl/schema-ast/src/ast/argument.rs index 8222806e1e16..3c65490e4469 100644 --- a/psl/schema-ast/src/ast/argument.rs +++ b/psl/schema-ast/src/ast/argument.rs @@ -1,5 +1,7 @@ +use alloc::vec::Vec; +use core::fmt::{Display, Formatter}; + use super::{Expression, Identifier, Span, WithSpan}; -use std::fmt::{Display, Formatter}; /// A list of arguments inside parentheses. #[derive(Debug, Clone, Default)] @@ -28,7 +30,7 @@ pub struct ArgumentsList { } impl ArgumentsList { - pub(crate) fn iter(&self) -> std::slice::Iter<'_, Argument> { + pub(crate) fn iter(&self) -> core::slice::Iter<'_, Argument> { self.arguments.iter() } } @@ -55,7 +57,7 @@ pub struct Argument { } impl Display for Argument { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { if let Some(name) = &self.name { f.write_str(&name.name)?; f.write_str(": ")?; diff --git a/psl/schema-ast/src/ast/attribute.rs b/psl/schema-ast/src/ast/attribute.rs index f664e4da2c5e..6f58edc48bed 100644 --- a/psl/schema-ast/src/ast/attribute.rs +++ b/psl/schema-ast/src/ast/attribute.rs @@ -1,5 +1,5 @@ use super::{ArgumentsList, EnumValueId, Identifier, Span, WithIdentifier, WithSpan}; -use std::ops::Index; +use core::ops::Index; /// An attribute (following `@` or `@@``) on a model, model field, enum, enum value or composite /// type field. diff --git a/psl/schema-ast/src/ast/comment.rs b/psl/schema-ast/src/ast/comment.rs index b7463b14a9d9..c370c3207348 100644 --- a/psl/schema-ast/src/ast/comment.rs +++ b/psl/schema-ast/src/ast/comment.rs @@ -1,3 +1,5 @@ +use alloc::string::String; + #[derive(Debug, Clone, PartialEq)] pub(crate) struct Comment { pub text: String, diff --git a/psl/schema-ast/src/ast/composite_type.rs b/psl/schema-ast/src/ast/composite_type.rs index e0e42d405aca..5e830314db18 100644 --- a/psl/schema-ast/src/ast/composite_type.rs +++ b/psl/schema-ast/src/ast/composite_type.rs @@ -1,3 +1,5 @@ +use alloc::vec::Vec; + use crate::ast::{Comment, Field, FieldId, Identifier, SchemaAst, Span}; use super::{WithDocumentation, WithIdentifier}; @@ -59,7 +61,7 @@ impl CompositeType { #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct CompositeTypeId(pub(super) u32); -impl std::ops::Index for SchemaAst { +impl core::ops::Index for SchemaAst { type Output = CompositeType; fn index(&self, index: CompositeTypeId) -> &Self::Output { @@ -67,7 +69,7 @@ impl std::ops::Index for SchemaAst { } } -impl std::ops::Index for CompositeType { +impl core::ops::Index for CompositeType { type Output = Field; fn index(&self, index: FieldId) -> &Self::Output { diff --git a/psl/schema-ast/src/ast/enum.rs b/psl/schema-ast/src/ast/enum.rs index 990e599d0e7f..dc8138804dff 100644 --- a/psl/schema-ast/src/ast/enum.rs +++ b/psl/schema-ast/src/ast/enum.rs @@ -1,3 +1,5 @@ +use alloc::vec::Vec; + use super::{Attribute, Comment, Identifier, Span, WithAttributes, WithDocumentation, WithIdentifier, WithSpan}; /// An opaque identifier for a value in an AST enum. Use the @@ -12,7 +14,7 @@ impl EnumValueId { pub const MAX: EnumValueId = EnumValueId(u32::MAX); } -impl std::ops::Index for Enum { +impl core::ops::Index for Enum { type Output = EnumValue; fn index(&self, index: EnumValueId) -> &Self::Output { diff --git a/psl/schema-ast/src/ast/expression.rs b/psl/schema-ast/src/ast/expression.rs index 6c239adf92fb..e54006ad2678 100644 --- a/psl/schema-ast/src/ast/expression.rs +++ b/psl/schema-ast/src/ast/expression.rs @@ -1,5 +1,10 @@ +use alloc::{ + string::{String, ToString}, + vec::Vec, +}; +use core::fmt; + use crate::ast::{self, Span}; -use std::fmt; /// Represents arbitrary, even nested, expressions. #[derive(Debug, Clone)] diff --git a/psl/schema-ast/src/ast/field.rs b/psl/schema-ast/src/ast/field.rs index 394381a2f3b1..aea874c5dc59 100644 --- a/psl/schema-ast/src/ast/field.rs +++ b/psl/schema-ast/src/ast/field.rs @@ -1,4 +1,5 @@ -use std::fmt::Display; +use alloc::{string::String, vec::Vec}; +use core::fmt::Display; use super::{ Attribute, Comment, Identifier, Span, WithAttributes, WithDocumentation, WithIdentifier, WithName, WithSpan, @@ -43,7 +44,7 @@ pub struct Field { } impl Display for Field { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let extension = if self.arity.is_list() { "[]" } else if self.arity.is_optional() { diff --git a/psl/schema-ast/src/ast/find_at_position.rs b/psl/schema-ast/src/ast/find_at_position.rs index 12b2dc25eed0..c3b4cae6debc 100644 --- a/psl/schema-ast/src/ast/find_at_position.rs +++ b/psl/schema-ast/src/ast/find_at_position.rs @@ -46,7 +46,7 @@ impl ast::SchemaAst { /// Do a binary search for the `Top` at the given byte offset. pub fn find_top_at_position(&self, position: usize) -> Option { - use std::cmp::Ordering; + use core::cmp::Ordering; let top_idx = self.tops.binary_search_by(|top| { let span = top.span(); diff --git a/psl/schema-ast/src/ast/find_at_position/attribute.rs b/psl/schema-ast/src/ast/find_at_position/attribute.rs index b4501dd28ae4..ea7831672422 100644 --- a/psl/schema-ast/src/ast/find_at_position/attribute.rs +++ b/psl/schema-ast/src/ast/find_at_position/attribute.rs @@ -1,4 +1,9 @@ -use crate::ast::{self}; +use alloc::{ + string::{String, ToString}, + vec::Vec, +}; + +use crate::ast; use super::{ExpressionPosition, WithSpan}; diff --git a/psl/schema-ast/src/ast/find_at_position/enum.rs b/psl/schema-ast/src/ast/find_at_position/enum.rs index 3e46d4ee028c..cd7654754ff4 100644 --- a/psl/schema-ast/src/ast/find_at_position/enum.rs +++ b/psl/schema-ast/src/ast/find_at_position/enum.rs @@ -1,3 +1,5 @@ +use alloc::vec::Vec; + use super::{AttributePosition, WithName, WithSpan}; use crate::ast::{self}; diff --git a/psl/schema-ast/src/ast/find_at_position/expression.rs b/psl/schema-ast/src/ast/find_at_position/expression.rs index d5ba15d578db..3345705bcfc4 100644 --- a/psl/schema-ast/src/ast/find_at_position/expression.rs +++ b/psl/schema-ast/src/ast/find_at_position/expression.rs @@ -1,4 +1,6 @@ -use crate::ast::{self}; +use alloc::vec::Vec; + +use crate::ast; use super::WithSpan; diff --git a/psl/schema-ast/src/ast/generator_config.rs b/psl/schema-ast/src/ast/generator_config.rs index cb7689f30e97..b5b05bdbdd11 100644 --- a/psl/schema-ast/src/ast/generator_config.rs +++ b/psl/schema-ast/src/ast/generator_config.rs @@ -1,3 +1,5 @@ +use alloc::vec::Vec; + use super::{Comment, Identifier, Span, WithDocumentation, WithIdentifier, WithSpan}; use crate::ast::config::ConfigBlockProperty; diff --git a/psl/schema-ast/src/ast/identifier.rs b/psl/schema-ast/src/ast/identifier.rs index 92eccefecf1a..603d0a56e88e 100644 --- a/psl/schema-ast/src/ast/identifier.rs +++ b/psl/schema-ast/src/ast/identifier.rs @@ -1,3 +1,5 @@ +use alloc::{borrow::ToOwned, string::String}; + use super::{Span, WithSpan}; use diagnostics::FileId; diff --git a/psl/schema-ast/src/ast/indentation_type.rs b/psl/schema-ast/src/ast/indentation_type.rs index a049eba3f03c..8f63aa7acc44 100644 --- a/psl/schema-ast/src/ast/indentation_type.rs +++ b/psl/schema-ast/src/ast/indentation_type.rs @@ -1,4 +1,4 @@ -use std::fmt; +use core::fmt; /// Defines the indentation of a PSL block. #[derive(Debug, Clone, Copy, PartialEq)] diff --git a/psl/schema-ast/src/ast/model.rs b/psl/schema-ast/src/ast/model.rs index 4df12a95ced6..2c16af02cc20 100644 --- a/psl/schema-ast/src/ast/model.rs +++ b/psl/schema-ast/src/ast/model.rs @@ -1,3 +1,5 @@ +use alloc::vec::Vec; + use super::{Attribute, Comment, Field, Identifier, Span, WithAttributes, WithDocumentation, WithIdentifier, WithSpan}; /// An opaque identifier for a field in an AST model. Use the @@ -12,7 +14,7 @@ impl FieldId { pub const MAX: FieldId = FieldId(u32::MAX); } -impl std::ops::Index for Model { +impl core::ops::Index for Model { type Output = Field; fn index(&self, index: FieldId) -> &Self::Output { diff --git a/psl/schema-ast/src/ast/newline_type.rs b/psl/schema-ast/src/ast/newline_type.rs index 061f77c24e14..93b6f4243d8f 100644 --- a/psl/schema-ast/src/ast/newline_type.rs +++ b/psl/schema-ast/src/ast/newline_type.rs @@ -1,4 +1,4 @@ -use std::fmt; +use core::fmt; /// Defines the newline type of a PSL block. #[derive(Default, Debug, Clone, Copy, PartialEq)] diff --git a/psl/schema-ast/src/ast/source_config.rs b/psl/schema-ast/src/ast/source_config.rs index 31d75ce1a9a5..125975437556 100644 --- a/psl/schema-ast/src/ast/source_config.rs +++ b/psl/schema-ast/src/ast/source_config.rs @@ -1,3 +1,5 @@ +use alloc::vec::Vec; + use super::{Comment, ConfigBlockProperty, Identifier, Span, WithDocumentation, WithIdentifier, WithSpan}; /// A source block declaration. diff --git a/psl/schema-ast/src/lib.rs b/psl/schema-ast/src/lib.rs index dfa6d76f02f3..24d75a1840b5 100644 --- a/psl/schema-ast/src/lib.rs +++ b/psl/schema-ast/src/lib.rs @@ -2,6 +2,10 @@ #![deny(rust_2018_idioms, unsafe_code)] #![allow(clippy::derive_partial_eq_without_eq)] +#![no_std] + +#[macro_use] +extern crate alloc; pub use self::{parser::parse_schema, reformat::reformat, source_file::SourceFile}; @@ -25,11 +29,11 @@ mod source_file; ///hi"#; ///assert_eq!(r#""oh\nhi""#, &string_literal(input).to_string()); /// ``` -pub fn string_literal(s: &str) -> impl std::fmt::Display + '_ { +pub fn string_literal(s: &str) -> impl core::fmt::Display + '_ { struct StringLiteral<'a>(&'a str); - impl std::fmt::Display for StringLiteral<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + impl core::fmt::Display for StringLiteral<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.write_str("\"")?; for c in self.0.char_indices() { match c { diff --git a/psl/schema-ast/src/parser/parse_comments.rs b/psl/schema-ast/src/parser/parse_comments.rs index 725afa953f06..0271ea21792b 100644 --- a/psl/schema-ast/src/parser/parse_comments.rs +++ b/psl/schema-ast/src/parser/parse_comments.rs @@ -1,3 +1,5 @@ +use alloc::vec::Vec; + use super::{ Rule, helpers::{Pair, parsing_catch_all}, diff --git a/psl/schema-ast/src/parser/parse_composite_type.rs b/psl/schema-ast/src/parser/parse_composite_type.rs index 5544a65fcb56..c672bfda6e6e 100644 --- a/psl/schema-ast/src/parser/parse_composite_type.rs +++ b/psl/schema-ast/src/parser/parse_composite_type.rs @@ -6,6 +6,7 @@ use super::{ parse_field::parse_field, }; use crate::ast; +use alloc::vec::Vec; use diagnostics::{DatamodelError, Diagnostics, FileId, Span}; pub(crate) fn parse_composite_type( diff --git a/psl/schema-ast/src/parser/parse_enum.rs b/psl/schema-ast/src/parser/parse_enum.rs index 9e9fbd6b754b..c996efaeb30f 100644 --- a/psl/schema-ast/src/parser/parse_enum.rs +++ b/psl/schema-ast/src/parser/parse_enum.rs @@ -5,6 +5,7 @@ use super::{ parse_comments::*, }; use crate::ast::{self, Attribute, Comment, Enum, EnumValue, Identifier}; +use alloc::vec::Vec; use diagnostics::{DatamodelError, Diagnostics, FileId, Span}; pub fn parse_enum( diff --git a/psl/schema-ast/src/parser/parse_expression.rs b/psl/schema-ast/src/parser/parse_expression.rs index e594cb41ec2a..0a4710245e2e 100644 --- a/psl/schema-ast/src/parser/parse_expression.rs +++ b/psl/schema-ast/src/parser/parse_expression.rs @@ -1,3 +1,8 @@ +use alloc::{ + string::{String, ToString}, + vec::Vec, +}; + use super::{ Rule, helpers::{Pair, parsing_catch_all}, diff --git a/psl/schema-ast/src/parser/parse_field.rs b/psl/schema-ast/src/parser/parse_field.rs index ffa868e38f8f..d45e19432dd8 100644 --- a/psl/schema-ast/src/parser/parse_field.rs +++ b/psl/schema-ast/src/parser/parse_field.rs @@ -6,6 +6,7 @@ use super::{ parse_types::parse_field_type, }; use crate::ast::{self, *}; +use alloc::vec::Vec; use diagnostics::{DatamodelError, Diagnostics, FileId}; pub(crate) fn parse_field( diff --git a/psl/schema-ast/src/parser/parse_model.rs b/psl/schema-ast/src/parser/parse_model.rs index 25e91433e071..ebf7df59c69d 100644 --- a/psl/schema-ast/src/parser/parse_model.rs +++ b/psl/schema-ast/src/parser/parse_model.rs @@ -6,6 +6,7 @@ use super::{ parse_field::parse_field, }; use crate::ast::{self, *}; +use alloc::vec::Vec; use diagnostics::{DatamodelError, Diagnostics, FileId}; pub(crate) fn parse_model( diff --git a/psl/schema-ast/src/parser/parse_schema.rs b/psl/schema-ast/src/parser/parse_schema.rs index 674b11c729e8..2b2311df76c6 100644 --- a/psl/schema-ast/src/parser/parse_schema.rs +++ b/psl/schema-ast/src/parser/parse_schema.rs @@ -3,6 +3,7 @@ use super::{ parse_model::parse_model, parse_source_and_generator::parse_config_block, parse_view::parse_view, }; use crate::ast::*; +use alloc::{string::String, vec::Vec}; use diagnostics::{DatamodelError, Diagnostics, FileId}; use pest::Parser; @@ -97,7 +98,7 @@ pub fn parse_schema(datamodel_string: &str, diagnostics: &mut Diagnostics, file_ } fn get_expected_from_error(positives: &[Rule]) -> String { - use std::fmt::Write as _; + use core::fmt::Write as _; let mut out = String::with_capacity(positives.len() * 6); for positive in positives { diff --git a/psl/schema-ast/src/parser/parse_source_and_generator.rs b/psl/schema-ast/src/parser/parse_source_and_generator.rs index e5c458127bfd..2feead90de52 100644 --- a/psl/schema-ast/src/parser/parse_source_and_generator.rs +++ b/psl/schema-ast/src/parser/parse_source_and_generator.rs @@ -5,6 +5,7 @@ use super::{ parse_expression::parse_expression, }; use crate::ast::{self, *}; +use alloc::vec::Vec; use diagnostics::{DatamodelError, Diagnostics, FileId}; pub(crate) fn parse_config_block(pair: Pair<'_>, diagnostics: &mut Diagnostics, file_id: FileId) -> Top { diff --git a/psl/schema-ast/src/parser/parse_types.rs b/psl/schema-ast/src/parser/parse_types.rs index d70056aab56b..acecd1c55ac6 100644 --- a/psl/schema-ast/src/parser/parse_types.rs +++ b/psl/schema-ast/src/parser/parse_types.rs @@ -1,5 +1,6 @@ use super::{Rule, helpers::Pair}; use crate::{ast::*, parser::parse_expression::parse_expression}; +use alloc::string::ToString; use diagnostics::{DatamodelError, Diagnostics, FileId}; pub fn parse_field_type( diff --git a/psl/schema-ast/src/parser/parse_view.rs b/psl/schema-ast/src/parser/parse_view.rs index 0e02f349f2c8..8ea1fa32ebaf 100644 --- a/psl/schema-ast/src/parser/parse_view.rs +++ b/psl/schema-ast/src/parser/parse_view.rs @@ -6,6 +6,7 @@ use super::{ parse_field::parse_field, }; use crate::ast::{self, Attribute}; +use alloc::vec::Vec; use diagnostics::{DatamodelError, Diagnostics, FileId}; pub(crate) fn parse_view( diff --git a/psl/schema-ast/src/reformat.rs b/psl/schema-ast/src/reformat.rs index 4351c43332d5..8d41029a0d7e 100644 --- a/psl/schema-ast/src/reformat.rs +++ b/psl/schema-ast/src/reformat.rs @@ -2,8 +2,9 @@ use crate::{ parser::{PrismaDatamodelParser, Rule}, renderer::{LineWriteable, Renderer, TableFormat}, }; +use alloc::{string::String, vec::Vec}; +use core::iter::Peekable; use pest::Parser; -use std::iter::Peekable; type Pair<'a> = pest::iterators::Pair<'a, Rule>; diff --git a/psl/schema-ast/src/renderer.rs b/psl/schema-ast/src/renderer.rs index dc6bbc6cc9c0..78ee3f074896 100644 --- a/psl/schema-ast/src/renderer.rs +++ b/psl/schema-ast/src/renderer.rs @@ -1,5 +1,6 @@ mod table; +use alloc::string::String; pub(crate) use table::TableFormat; pub(crate) trait LineWriteable { diff --git a/psl/schema-ast/src/renderer/table.rs b/psl/schema-ast/src/renderer/table.rs index 543bd9ac6cb8..4bb9e242bfe1 100644 --- a/psl/schema-ast/src/renderer/table.rs +++ b/psl/schema-ast/src/renderer/table.rs @@ -1,5 +1,7 @@ +use alloc::{string::String, vec::Vec}; +use core::cmp::max; + use super::LineWriteable; -use std::cmp::max; const COLUMN_SPACING: usize = 1; @@ -19,7 +21,7 @@ pub(crate) struct TableFormat { impl TableFormat { fn reset(&mut self) { - std::mem::take(self); + core::mem::take(self); } pub(crate) fn column_locked_writer_for(&mut self, index: usize) -> &mut String { diff --git a/psl/schema-ast/src/source_file.rs b/psl/schema-ast/src/source_file.rs index 6c8b1b19b17b..2f787bababef 100644 --- a/psl/schema-ast/src/source_file.rs +++ b/psl/schema-ast/src/source_file.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use alloc::{borrow::ToOwned, boxed::Box, string::String, sync::Arc}; use serde::{Deserialize, Deserializer}; @@ -83,8 +83,8 @@ enum Contents { Allocated(Arc), } -impl std::hash::Hash for Contents { - fn hash(&self, state: &mut H) { +impl core::hash::Hash for Contents { + fn hash(&self, state: &mut H) { match self { Contents::Static(s) => (*s).hash(state), Contents::Allocated(s) => { diff --git a/quaint/Cargo.toml b/quaint/Cargo.toml index 50dc8cdd7bda..5ed1be0788ee 100644 --- a/quaint/Cargo.toml +++ b/quaint/Cargo.toml @@ -1,11 +1,11 @@ [package] authors = [ - "Julius de Bruijn ", - "Katharina Fey ", - "Tom Houlé ", - "Emanuel Jöbstl ", - "Matthias Oertel ", - "Dominic Petrick ", + "Julius de Bruijn ", + "Katharina Fey ", + "Tom Houlé ", + "Emanuel Jöbstl ", + "Matthias Oertel ", + "Dominic Petrick ", ] description = "An abstraction layer for SQL databases." documentation = "https://docs.rs/quaint/" @@ -29,49 +29,59 @@ docs = [] expose-drivers = [] all-native = [ - "postgresql-native", - "mysql-native", - "mssql-native", - "sqlite-native", + "postgresql-native", + "mysql-native", + "mssql-native", + "sqlite-native", ] vendored-openssl = [ - "postgres-native-tls/vendored-openssl", - "mysql_async/vendored-openssl", + "postgres-native-tls/vendored-openssl", + "mysql_async/vendored-openssl", ] postgresql-native = [ - "postgresql", - "dep:native-tls", - "dep:tokio-postgres", - "dep:postgres-types", - "dep:postgres-native-tls", - "dep:bytes", - "dep:tokio", - "dep:bit-vec", - "dep:lru-cache", - "dep:byteorder", - "dep:tokio-tungstenite", + "postgresql", + "dep:native-tls", + "dep:tokio-postgres", + "dep:postgres-types", + "dep:postgres-native-tls", + "dep:bytes", + "dep:tokio", + "dep:bit-vec", + "dep:lru-cache", + "dep:byteorder", + "dep:tokio-tungstenite", + "tracing-futures/std", ] postgresql = [] -mssql-native = ["mssql", "dep:tiberius", "dep:tokio-util", "tokio/time", "tokio/net"] +mssql-native = [ + "mssql", + "dep:tiberius", + "dep:tokio-util", + "tokio/time", + "tokio/net", +] mssql = [] mysql-native = ["mysql", "dep:mysql_async", "tokio/time", "dep:lru-cache"] mysql = ["chrono/std"] pooled = ["dep:mobc"] + sqlite-native = ["sqlite", "rusqlite/bundled", "tokio/sync"] sqlite = [] fmt-sql = ["dep:sqlformat"] +connector = ["dep:telemetry"] + [dependencies] bigdecimal.workspace = true connection-string.workspace = true percent-encoding.workspace = true -telemetry.workspace = true +telemetry = { workspace = true, optional = true } tracing.workspace = true tracing-futures.workspace = true async-trait.workspace = true @@ -138,43 +148,43 @@ optional = true workspace = true optional = true features = [ - "sql-browser-tokio", - "chrono", - "tds73", - "bigdecimal", - "native-tls", - "winauth", + "sql-browser-tokio", + "chrono", + "tds73", + "bigdecimal", + "native-tls", + "winauth", ] [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.tiberius] workspace = true optional = true features = [ - "sql-browser-tokio", - "vendored-openssl", - "chrono", - "bigdecimal", - "tds73", - "winauth", + "sql-browser-tokio", + "vendored-openssl", + "chrono", + "bigdecimal", + "tds73", + "winauth", ] [dependencies.tokio-postgres] workspace = true features = [ - "with-uuid-1", - "with-chrono-0_4", - "with-serde_json-1", - "with-bit-vec-0_6", + "with-uuid-1", + "with-chrono-0_4", + "with-serde_json-1", + "with-bit-vec-0_6", ] optional = true [dependencies.postgres-types] workspace = true features = [ - "with-uuid-1", - "with-chrono-0_4", - "with-serde_json-1", - "with-bit-vec-0_6", + "with-uuid-1", + "with-chrono-0_4", + "with-serde_json-1", + "with-bit-vec-0_6", ] optional = true diff --git a/quaint/src/ast.rs b/quaint/src/ast.rs index 0a5f1390b92d..c47b5d04c46b 100644 --- a/quaint/src/ast.rs +++ b/quaint/src/ast.rs @@ -53,5 +53,5 @@ pub use select::{DistinctType, Select}; pub use table::*; pub use union::Union; pub use update::*; +pub(crate) use values::NativeColumnType; pub use values::{IntoRaw, OpaqueType, Raw, Value, ValueType, Values}; -pub(crate) use values::{NativeColumnType, Params}; diff --git a/quaint/src/error/mod.rs b/quaint/src/error/mod.rs index 2b4bc9edd03d..9593ae92badd 100644 --- a/quaint/src/error/mod.rs +++ b/quaint/src/error/mod.rs @@ -5,6 +5,7 @@ pub mod native; pub(crate) mod name; +#[cfg(feature = "connector")] use crate::connector::IsolationLevel; use std::{borrow::Cow, fmt, num}; use thiserror::Error; @@ -15,13 +16,13 @@ use std::time::Duration; #[cfg(not(target_arch = "wasm32"))] pub use native::NativeErrorKind; -#[cfg(feature = "mssql")] +#[cfg(all(feature = "mssql", feature = "connector"))] pub use crate::connector::mssql::MssqlError; -#[cfg(feature = "mysql")] +#[cfg(all(feature = "mysql", feature = "connector"))] pub use crate::connector::mysql::MysqlError; -#[cfg(feature = "postgresql")] +#[cfg(all(feature = "postgresql", feature = "connector"))] pub use crate::connector::postgres::PostgresError; -#[cfg(feature = "sqlite")] +#[cfg(all(feature = "sqlite", feature = "connector"))] pub use crate::connector::sqlite::SqliteError; pub(crate) use name::Name; @@ -309,6 +310,7 @@ impl ErrorKind { }) } + #[cfg(feature = "connector")] pub fn invalid_isolation_level(isolation_level: &IsolationLevel) -> Self { Self::InvalidIsolationLevel(isolation_level.to_string()) } diff --git a/quaint/src/lib.rs b/quaint/src/lib.rs index f2ad0e4fe97a..7db2600d55fc 100644 --- a/quaint/src/lib.rs +++ b/quaint/src/lib.rs @@ -117,11 +117,13 @@ pub use bigdecimal; pub use chrono; pub mod ast; +#[cfg(feature = "connector")] pub mod connector; pub mod error; -#[cfg(feature = "pooled")] +#[cfg(all(feature = "pooled", feature = "connector"))] pub mod pooled; pub mod prelude; +#[cfg(feature = "connector")] pub mod single; pub mod visitor; diff --git a/quaint/src/macros.rs b/quaint/src/macros.rs index 63cf8ec2fa46..92dfc3b25645 100644 --- a/quaint/src/macros.rs +++ b/quaint/src/macros.rs @@ -1,5 +1,3 @@ -use crate::{Value, connector::ColumnType}; - /// Convert given set of tuples into `Values`. /// /// ```rust @@ -250,9 +248,12 @@ macro_rules! test_type { }; } -#[allow(dead_code)] -pub(crate) fn assert_matching_value_and_column_type(col_type: &ColumnType, value: &Value) { - let inferred_column_type = ColumnType::from(&value.typed); +#[cfg(test)] +pub(crate) fn assert_matching_value_and_column_type( + col_type: &crate::connector::ColumnType, + value: &crate::ast::Value, +) { + let inferred_column_type = crate::connector::ColumnType::from(&value.typed); if !inferred_column_type.is_unknown() { assert_eq!(col_type, &inferred_column_type); diff --git a/quaint/src/prelude.rs b/quaint/src/prelude.rs index 7691fc02dd9f..4a5f2777ab8f 100644 --- a/quaint/src/prelude.rs +++ b/quaint/src/prelude.rs @@ -1,5 +1,6 @@ //! A "prelude" for users of the `quaint` crate. pub use crate::ast::*; +#[cfg(feature = "connector")] pub use crate::connector::{ ColumnType, ConnectionInfo, DefaultTransaction, ExternalConnectionInfo, NativeConnectionInfo, Queryable, ResultRow, ResultSet, SqlFamily, TransactionCapable, diff --git a/query-compiler/query-compiler-wasm/Cargo.toml b/query-compiler/query-compiler-wasm/Cargo.toml index 3cb6261cd617..0c89cdd58db7 100644 --- a/query-compiler/query-compiler-wasm/Cargo.toml +++ b/query-compiler/query-compiler-wasm/Cargo.toml @@ -15,7 +15,7 @@ workspace = true psl.workspace = true quaint.workspace = true tracing.workspace = true - +hashbrown.workspace = true js-sys.workspace = true serde.workspace = true serde_json.workspace = true diff --git a/query-compiler/query-compiler-wasm/src/compiler.rs b/query-compiler/query-compiler-wasm/src/compiler.rs index 464f72c3cef3..6c0516798965 100644 --- a/query-compiler/query-compiler-wasm/src/compiler.rs +++ b/query-compiler/query-compiler-wasm/src/compiler.rs @@ -1,3 +1,6 @@ +use alloc::{boxed::Box, string::String, sync::Arc, vec::Vec}; + +use hashbrown::HashMap; use psl::ConnectorRegistry; use quaint::connector::ConnectionInfo; use query_compiler::{CompileError, Expression, TranslateError}; @@ -7,7 +10,6 @@ use query_core::{ }; use request_handlers::{HandlerError, RequestBody}; use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, sync::Arc}; use tsify::Tsify; use user_facing_errors::UserFacingError; use wasm_bindgen::{JsValue, prelude::wasm_bindgen}; @@ -27,31 +29,6 @@ const CONNECTOR_REGISTRY: ConnectorRegistry<'_> = &[ psl::builtin_connectors::COCKROACH, ]; -#[wasm_bindgen] -extern "C" { - /// This function registers the reason for a Wasm panic via the - /// JS function `globalThis.PRISMA_WASM_PANIC_REGISTRY.set_message()` - #[wasm_bindgen(js_namespace = ["global", "PRISMA_WASM_PANIC_REGISTRY"], js_name = "set_message")] - fn prisma_set_wasm_panic_message(s: &str); -} - -/// Registers a singleton panic hook that will register the reason for the Wasm panic in JS. -/// Without this, the panic message would be lost: you'd see `RuntimeError: unreachable` message in JS, -/// with no reference to the Rust function and line that panicked. -/// This function should be manually called before any other public function in this module. -/// Note: no method is safe to call after a panic has occurred. -fn register_panic_hook() { - use std::sync::Once; - static SET_HOOK: Once = Once::new(); - - SET_HOOK.call_once(|| { - std::panic::set_hook(Box::new(|info| { - let message = &info.to_string(); - prisma_set_wasm_panic_message(message); - })); - }); -} - #[derive(Deserialize, Tsify)] #[serde(rename_all = "camelCase")] #[tsify(from_wasm_abi)] @@ -86,7 +63,6 @@ impl QueryCompiler { ); tracing::info!(git_hash = env!("GIT_HASH"), "Starting query-compiler-wasm"); - register_panic_hook(); Ok(Self { schema, diff --git a/query-compiler/query-compiler-wasm/src/lib.rs b/query-compiler/query-compiler-wasm/src/lib.rs index e46abcf798b1..e8ed7f34d1d6 100644 --- a/query-compiler/query-compiler-wasm/src/lib.rs +++ b/query-compiler/query-compiler-wasm/src/lib.rs @@ -1,2 +1,8 @@ -pub mod compiler; -pub mod params; +#![no_std] + +#[macro_use] +extern crate alloc; + +mod compiler; +mod panic; +mod params; diff --git a/query-compiler/query-compiler-wasm/src/panic.rs b/query-compiler/query-compiler-wasm/src/panic.rs new file mode 100644 index 000000000000..548012bfa03d --- /dev/null +++ b/query-compiler/query-compiler-wasm/src/panic.rs @@ -0,0 +1,18 @@ +use core::panic::PanicInfo; + +use alloc::string::ToString; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +extern "C" { + /// This function registers the reason for a Wasm panic via the + /// JS function `globalThis.PRISMA_WASM_PANIC_REGISTRY.set_message()` + #[wasm_bindgen(js_namespace = ["global", "PRISMA_WASM_PANIC_REGISTRY"], js_name = "set_message")] + fn prisma_set_wasm_panic_message(s: &str); +} + +#[panic_handler] +fn panic2(info: &PanicInfo) -> ! { + prisma_set_wasm_panic_message(&info.to_string()); + core::intrinsics::abort() +} diff --git a/query-compiler/query-compiler-wasm/src/params.rs b/query-compiler/query-compiler-wasm/src/params.rs index b285d71775a6..a3825a188408 100644 --- a/query-compiler/query-compiler-wasm/src/params.rs +++ b/query-compiler/query-compiler-wasm/src/params.rs @@ -1,3 +1,4 @@ +use alloc::{borrow::ToOwned, string::String}; use quaint::prelude::{ExternalConnectionInfo, SqlFamily}; use serde::Deserialize; diff --git a/query-engine/connectors/query-connector/Cargo.toml b/query-engine/connectors/query-connector/Cargo.toml index d6d913d3226a..29196d249f10 100644 --- a/query-engine/connectors/query-connector/Cargo.toml +++ b/query-engine/connectors/query-connector/Cargo.toml @@ -17,4 +17,4 @@ thiserror.workspace = true user-facing-errors = { workspace = true, features = ["sql"] } uuid.workspace = true indexmap.workspace = true -telemetry.workspace = true +telemetry = { workspace = true, optional = true } diff --git a/query-engine/connectors/query-connector/src/interface.rs b/query-engine/connectors/query-connector/src/interface.rs index 3db5a11a3b5c..347429b625f6 100644 --- a/query-engine/connectors/query-connector/src/interface.rs +++ b/query-engine/connectors/query-connector/src/interface.rs @@ -3,8 +3,12 @@ use async_trait::async_trait; use prisma_value::PrismaValue; use query_structure::*; use std::collections::HashMap; +#[cfg(feature = "telemetry")] use telemetry::TraceParent; +#[cfg(not(feature = "telemetry"))] +enum TraceParent {} + #[async_trait] pub trait Connector { /// Returns a connection to a data source. diff --git a/query-engine/core/Cargo.toml b/query-engine/core/Cargo.toml index df34d7688f6a..46d60d7bff3a 100644 --- a/query-engine/core/Cargo.toml +++ b/query-engine/core/Cargo.toml @@ -4,6 +4,8 @@ name = "query-core" version = "0.1.0" [features] +std = [] +executor = ["std", "telemetry", "connector", "tracing-subscriber"] metrics = ["prisma-metrics"] graphql-protocol = [] @@ -13,7 +15,7 @@ bigdecimal.workspace = true bon.workspace = true chrono.workspace = true connection-string.workspace = true -connector = { path = "../connectors/query-connector", package = "query-connector" } +connector = { path = "../connectors/query-connector", package = "query-connector", optional = true } crossbeam-channel.workspace = true psl.workspace = true futures.workspace = true @@ -22,9 +24,7 @@ itertools.workspace = true petgraph.workspace = true query-builder.workspace = true sql-query-builder.workspace = true -query-structure = { workspace = true, features = [ - "default_generators", -] } +query-structure = { workspace = true, features = ["default_generators"] } prisma-metrics = { workspace = true, optional = true } serde.workspace = true serde_json.workspace = true @@ -33,14 +33,16 @@ thiserror.workspace = true tokio = { workspace = true, features = ["macros", "rt", "time"] } tracing = { workspace = true, features = ["attributes"] } tracing-futures.workspace = true -tracing-subscriber = { workspace = true, features = ["env-filter"] } +tracing-subscriber = { workspace = true, features = [ + "env-filter", +], optional = true } user-facing-errors.workspace = true uuid.workspace = true cuid.workspace = true ulid.workspace = true schema.workspace = true crosstarget-utils.workspace = true -telemetry.workspace = true +telemetry = { workspace = true, optional = true } lru.workspace = true enumflags2.workspace = true derive_more.workspace = true diff --git a/query-engine/core/src/lib.rs b/query-engine/core/src/lib.rs index 99693ca630f8..efcaa28726da 100644 --- a/query-engine/core/src/lib.rs +++ b/query-engine/core/src/lib.rs @@ -1,39 +1,55 @@ #![deny(unsafe_code, rust_2018_idioms)] +#![cfg_attr(not(feature = "std"), no_std)] + +#[cfg(not(feature = "std"))] +extern crate alloc; #[macro_use] extern crate tracing; pub mod constants; +#[cfg(feature = "executor")] pub mod executor; pub mod protocol; pub mod query_document; pub mod query_graph_builder; pub mod relation_load_strategy; +#[cfg(feature = "executor")] pub mod response_ir; pub use self::{ error::{CoreError, ExtendedUserFacingError, FieldConversionError}, - executor::{QueryExecutor, TransactionOptions, with_sync_unevaluated_request_context}, - interactive_transactions::{TransactionError, TxId}, query_ast::*, query_document::*, query_graph::*, query_graph_builder::*, }; +#[cfg(feature = "executor")] +pub use self::{ + executor::{QueryExecutor, TransactionOptions, with_sync_unevaluated_request_context}, + interactive_transactions::{TransactionError, TxId}, +}; + +#[cfg(feature = "executor")] pub use connector::{ Connector, error::{ConnectorError, ErrorKind as ConnectorErrorKind}, }; mod error; +#[cfg(feature = "executor")] mod interactive_transactions; +#[cfg(feature = "executor")] mod interpreter; +#[cfg(feature = "executor")] mod metrics; mod query_ast; mod query_graph; +#[cfg(feature = "executor")] mod result_ast; +#[cfg(feature = "executor")] use self::{ executor::*, interactive_transactions::*, diff --git a/query-engine/query-structure/Cargo.toml b/query-engine/query-structure/Cargo.toml index dc15bc6370a5..1fda7d9464d4 100644 --- a/query-engine/query-structure/Cargo.toml +++ b/query-engine/query-structure/Cargo.toml @@ -17,10 +17,18 @@ ulid = { workspace = true, optional = true } nanoid = { workspace = true, optional = true } chrono.workspace = true indexmap.workspace = true +hashbrown.workspace = true [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { workspace = true, features = ["js"] } [features] # Support for generating default UUID, CUID, ULID, nanoid and datetime values. -default_generators = ["uuid/v4", "uuid/v7", "cuid", "ulid", "nanoid"] +default_generators = [ + "uuid/v4", + "uuid/v7", + "cuid", + "ulid", + "ulid/std", + "nanoid", +] diff --git a/query-engine/query-structure/src/aggregate_selection.rs b/query-engine/query-structure/src/aggregate_selection.rs index 13582bd29582..ea683bf1e635 100644 --- a/query-engine/query-structure/src/aggregate_selection.rs +++ b/query-engine/query-structure/src/aggregate_selection.rs @@ -1,4 +1,5 @@ -use std::slice; +use alloc::vec::Vec; +use core::slice; use itertools::Either; use psl::schema_ast::ast::FieldArity; diff --git a/query-engine/query-structure/src/composite_type.rs b/query-engine/query-structure/src/composite_type.rs index 0add62884f57..ee89557533a8 100644 --- a/query-engine/query-structure/src/composite_type.rs +++ b/query-engine/query-structure/src/composite_type.rs @@ -24,8 +24,8 @@ impl CompositeType { } } -impl std::fmt::Debug for CompositeType { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for CompositeType { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_tuple("CompositeType").field(&self.name()).finish() } } diff --git a/query-engine/query-structure/src/convert.rs b/query-engine/query-structure/src/convert.rs index 91f8470c3c1e..a8fc81cc08a5 100644 --- a/query-engine/query-structure/src/convert.rs +++ b/query-engine/query-structure/src/convert.rs @@ -1,5 +1,6 @@ +use alloc::sync::Arc; + use crate::InternalDataModel; -use std::sync::Arc; pub fn convert(schema: Arc) -> InternalDataModel { InternalDataModel { schema } diff --git a/query-engine/query-structure/src/default_value.rs b/query-engine/query-structure/src/default_value.rs index 46ad7016c4bf..eff4a536cb38 100644 --- a/query-engine/query-structure/src/default_value.rs +++ b/query-engine/query-structure/src/default_value.rs @@ -1,5 +1,10 @@ +use alloc::{ + borrow::ToOwned, + string::{String, ToString}, + vec::Vec, +}; +use core::fmt; use prisma_value::{PrismaValue, PrismaValueType}; -use std::fmt; /// Represents a default specified on a field. #[derive(Clone, PartialEq, Debug)] @@ -278,7 +283,7 @@ pub enum ValueGeneratorFn { } impl ValueGeneratorFn { - fn new(name: &str, args: &[PrismaValue]) -> std::result::Result { + fn new(name: &str, args: &[PrismaValue]) -> core::result::Result { match name { "ulid" => Ok(Self::Ulid), "cuid" => match args[..] { @@ -381,6 +386,8 @@ impl fmt::Debug for DefaultKind { #[cfg(test)] mod tests { + use alloc::string::ToString; + use super::{DefaultValue, ValueGenerator}; #[test] diff --git a/query-engine/query-structure/src/distinct.rs b/query-engine/query-structure/src/distinct.rs index d2fb25cbb9ea..03dbf3b10281 100644 --- a/query-engine/query-structure/src/distinct.rs +++ b/query-engine/query-structure/src/distinct.rs @@ -38,7 +38,7 @@ pub fn native_distinct_compatible_with_order_by( mod tests { use super::*; - use std::sync::Arc; + use alloc::sync::Arc; use crate::{ScalarFieldRef, native_distinct_compatible_with_order_by}; diff --git a/query-engine/query-structure/src/error.rs b/query-engine/query-structure/src/error.rs index 438f7f35e18c..5bcd31ef64f7 100644 --- a/query-engine/query-structure/src/error.rs +++ b/query-engine/query-structure/src/error.rs @@ -1,3 +1,4 @@ +use alloc::string::String; use thiserror::Error; #[derive(Debug, Error, PartialEq)] diff --git a/query-engine/query-structure/src/field/composite.rs b/query-engine/query-structure/src/field/composite.rs index ea17715edab1..f7de1a543c40 100644 --- a/query-engine/query-structure/src/field/composite.rs +++ b/query-engine/query-structure/src/field/composite.rs @@ -1,9 +1,9 @@ use crate::{CompositeType, parent_container::ParentContainer}; +use core::fmt::{Debug, Display}; use psl::{ parser_database::{self as db, ScalarFieldId}, schema_ast::ast::{self, FieldArity}, }; -use std::fmt::{Debug, Display}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum CompositeFieldId { @@ -75,13 +75,13 @@ impl CompositeField { } impl Display for CompositeField { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}.{}", self.container().name(), self.name()) } } -impl std::fmt::Debug for CompositeField { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for CompositeField { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_tuple("CompositeField") .field(&format!("{}.{}", self.container().name(), self.name())) .finish() diff --git a/query-engine/query-structure/src/field/mod.rs b/query-engine/query-structure/src/field/mod.rs index 489334111df9..aa1c2145b953 100644 --- a/query-engine/query-structure/src/field/mod.rs +++ b/query-engine/query-structure/src/field/mod.rs @@ -2,6 +2,11 @@ mod composite; mod relation; mod scalar; +use alloc::{ + borrow::{Cow, ToOwned}, + boxed::Box, + vec::Vec, +}; pub use composite::*; use prisma_value::PrismaValueType; pub use relation::*; @@ -12,7 +17,6 @@ use psl::{ parser_database::{EnumId, ScalarType, walkers}, schema_ast::ast::FieldArity, }; -use std::{borrow::Cow, hash::Hash}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Field { @@ -207,8 +211,8 @@ impl Type { } } -impl std::fmt::Debug for Type { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Type { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_tuple("TypeIdentifier") .field(&format!("{:?}", self.id)) .finish() diff --git a/query-engine/query-structure/src/field/relation.rs b/query-engine/query-structure/src/field/relation.rs index a386067fb9ee..a6e07f791b50 100644 --- a/query-engine/query-structure/src/field/relation.rs +++ b/query-engine/query-structure/src/field/relation.rs @@ -1,9 +1,10 @@ use crate::prelude::*; +use alloc::{borrow::ToOwned, string::String, vec::Vec}; +use core::fmt::Display; use psl::parser_database::{ ast::FieldArity, walkers::{self, RelationFieldId}, }; -use std::fmt::Display; pub type RelationField = crate::Zipper; pub type RelationFieldRef = RelationField; @@ -145,14 +146,14 @@ impl RelationField { } impl Display for RelationField { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let walker = self.walker(); write!(f, "{}.{}", walker.model().name(), walker.name()) } } -impl std::fmt::Debug for RelationField { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for RelationField { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_tuple("RelationField") .field(&format!("{}.{}", self.model().name(), self.name(),)) .finish() diff --git a/query-engine/query-structure/src/field/scalar.rs b/query-engine/query-structure/src/field/scalar.rs index 1b4c6c4996c3..41d178a165c9 100644 --- a/query-engine/query-structure/src/field/scalar.rs +++ b/query-engine/query-structure/src/field/scalar.rs @@ -1,11 +1,12 @@ use crate::{DefaultKind, NativeTypeInstance, ValueGenerator, ast, parent_container::ParentContainer, prelude::*}; +use alloc::{borrow::ToOwned, string::String, vec::Vec}; use chrono::{DateTime, FixedOffset}; +use core::fmt::{Debug, Display}; use psl::{ generators::{DEFAULT_CUID_VERSION, DEFAULT_UUID_VERSION}, parser_database::{self as db, ScalarFieldType, ScalarType, walkers}, schema_ast::ast::FieldArity, }; -use std::fmt::{Debug, Display}; pub type ScalarField = crate::Zipper; pub type ScalarFieldRef = ScalarField; @@ -222,7 +223,7 @@ impl ScalarField { } impl Display for ScalarField { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}.{}", self.container().name(), self.name()) } } @@ -322,8 +323,8 @@ pub fn dml_default_kind(default_value: &ast::Expression, scalar_type: Option) -> std::fmt::Result { +impl core::fmt::Debug for ScalarField { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_tuple("ScalarField") .field(&format!("{}.{}", self.container().name(), self.name())) .finish() diff --git a/query-engine/query-structure/src/field_selection.rs b/query-engine/query-structure/src/field_selection.rs index 756c5023242d..21ffa618afb2 100644 --- a/query-engine/query-structure/src/field_selection.rs +++ b/query-engine/query-structure/src/field_selection.rs @@ -3,10 +3,15 @@ use crate::{ QueryArguments, RelationField, RelationFieldRef, ScalarField, ScalarFieldRef, SelectionResult, Type, TypeIdentifier, parent_container::ParentContainer, prisma_value_ext::PrismaValueExtensions, }; +use alloc::{ + borrow::{Cow, ToOwned}, + string::{String, ToString}, + vec::Vec, +}; +use core::fmt::Display; use itertools::Itertools; use prisma_value::PrismaValue; use psl::schema_ast::ast::FieldArity; -use std::{borrow::Cow, fmt::Display}; /// A selection of fields from a model. #[derive(Debug, Clone, PartialEq, Default, Hash, Eq)] @@ -206,7 +211,7 @@ impl FieldSelection { } pub fn merge_in_place(&mut self, other: FieldSelection) { - let this = std::mem::take(self); + let this = core::mem::take(self); *self = this.merge(other); } @@ -380,7 +385,7 @@ impl VirtualSelection { } impl Display for VirtualSelection { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let model = self.relation_field().model(); let model_name = model.name(); let (obj, field) = self.serialized_name(); @@ -591,7 +596,7 @@ impl From for SelectedField { } impl Display for FieldSelection { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!( f, "FieldSelection {{ fields: [{}] }}", @@ -604,7 +609,7 @@ impl Display for FieldSelection { } impl Display for SelectedField { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { SelectedField::Scalar(sf) => write!(f, "{sf}"), SelectedField::Composite(cs) => write!( @@ -638,7 +643,7 @@ impl From<&SelectionResult> for FieldSelection { impl IntoIterator for FieldSelection { type Item = SelectedField; - type IntoIter = std::vec::IntoIter; + type IntoIter = alloc::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { self.selections.into_iter() diff --git a/query-engine/query-structure/src/fields.rs b/query-engine/query-structure/src/fields.rs index b5386df2a812..1a00f30f0ee0 100644 --- a/query-engine/query-structure/src/fields.rs +++ b/query-engine/query-structure/src/fields.rs @@ -1,4 +1,5 @@ use crate::*; +use alloc::{borrow::ToOwned, string::ToString, vec::Vec}; use psl::parser_database::ScalarFieldType; #[derive(Debug, Clone)] diff --git a/query-engine/query-structure/src/filter/composite.rs b/query-engine/query-structure/src/filter/composite.rs index cd4851f2255e..d9e558cd9bbf 100644 --- a/query-engine/query-structure/src/filter/composite.rs +++ b/query-engine/query-structure/src/filter/composite.rs @@ -1,4 +1,5 @@ use crate::{CompositeCompare, CompositeFieldRef, filter::Filter}; +use alloc::boxed::Box; use prisma_value::PrismaValue; #[derive(Debug, Clone, PartialEq, Eq, Hash)] diff --git a/query-engine/query-structure/src/filter/into_filter.rs b/query-engine/query-structure/src/filter/into_filter.rs index 2515060cdf6d..fcf3bdc1edf3 100644 --- a/query-engine/query-structure/src/filter/into_filter.rs +++ b/query-engine/query-structure/src/filter/into_filter.rs @@ -1,3 +1,4 @@ +use alloc::vec::Vec; use itertools::Itertools; use super::*; diff --git a/query-engine/query-structure/src/filter/json.rs b/query-engine/query-structure/src/filter/json.rs index b0452106d19f..6148c6493f02 100644 --- a/query-engine/query-structure/src/filter/json.rs +++ b/query-engine/query-structure/src/filter/json.rs @@ -1,3 +1,5 @@ +use alloc::{boxed::Box, string::String, vec::Vec}; + use super::scalar::*; use crate::{Filter, JsonCompare, ScalarFieldRef, ScalarFilter}; diff --git a/query-engine/query-structure/src/filter/mod.rs b/query-engine/query-structure/src/filter/mod.rs index af351ae0d2bb..5a8578e83abb 100644 --- a/query-engine/query-structure/src/filter/mod.rs +++ b/query-engine/query-structure/src/filter/mod.rs @@ -14,6 +14,7 @@ mod record; mod relation; mod scalar; +use alloc::{borrow::ToOwned, boxed::Box, vec::Vec}; pub use compare::*; pub use composite::*; pub use into_filter::*; diff --git a/query-engine/query-structure/src/filter/record.rs b/query-engine/query-structure/src/filter/record.rs index 41ea87c47325..d8f67677f271 100644 --- a/query-engine/query-structure/src/filter/record.rs +++ b/query-engine/query-structure/src/filter/record.rs @@ -1,3 +1,5 @@ +use alloc::vec::Vec; + use crate::SelectionResult; use super::Filter; diff --git a/query-engine/query-structure/src/filter/relation.rs b/query-engine/query-structure/src/filter/relation.rs index d51e8ecb439e..63171d1b5896 100644 --- a/query-engine/query-structure/src/filter/relation.rs +++ b/query-engine/query-structure/src/filter/relation.rs @@ -1,3 +1,5 @@ +use alloc::boxed::Box; + use crate::{RelationCompare, RelationField, filter::Filter}; #[derive(Clone, PartialEq, Eq, Hash)] @@ -14,8 +16,8 @@ pub struct RelationFilter { pub condition: RelationCondition, } -impl std::fmt::Debug for RelationFilter { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for RelationFilter { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("RelationFilter") .field("field", &format!("{}", self.field)) .field("nested_filter", &self.nested_filter) diff --git a/query-engine/query-structure/src/filter/scalar/condition/mod.rs b/query-engine/query-structure/src/filter/scalar/condition/mod.rs index f60fa74ee986..614bc5f814b7 100644 --- a/query-engine/query-structure/src/filter/scalar/condition/mod.rs +++ b/query-engine/query-structure/src/filter/scalar/condition/mod.rs @@ -1,5 +1,6 @@ mod value; +use alloc::{boxed::Box, vec::Vec}; pub use value::{ConditionListValue, ConditionValue}; use super::*; diff --git a/query-engine/query-structure/src/filter/scalar/condition/value.rs b/query-engine/query-structure/src/filter/scalar/condition/value.rs index 12474b3ac95c..45e2f247b1ec 100644 --- a/query-engine/query-structure/src/filter/scalar/condition/value.rs +++ b/query-engine/query-structure/src/filter/scalar/condition/value.rs @@ -1,4 +1,5 @@ use crate::field::*; +use alloc::vec::Vec; use prisma_value::{PrismaListValue, PrismaValue}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] diff --git a/query-engine/query-structure/src/filter/scalar/mod.rs b/query-engine/query-structure/src/filter/scalar/mod.rs index a0c5a2d310fe..2eaf928ea090 100644 --- a/query-engine/query-structure/src/filter/scalar/mod.rs +++ b/query-engine/query-structure/src/filter/scalar/mod.rs @@ -7,7 +7,7 @@ pub use projection::*; use crate::*; -use std::collections::BTreeSet; +use alloc::{collections::BTreeSet, vec::Vec}; /// Filtering with a scalar value. From a GraphQL point of view this is in the /// head of the query: diff --git a/query-engine/query-structure/src/filter/scalar/projection.rs b/query-engine/query-structure/src/filter/scalar/projection.rs index 799ab0859cb9..e2191d74fe11 100644 --- a/query-engine/query-structure/src/filter/scalar/projection.rs +++ b/query-engine/query-structure/src/filter/scalar/projection.rs @@ -1,3 +1,5 @@ +use alloc::vec::Vec; + use crate::field::ScalarFieldRef; #[derive(Clone, PartialEq, Eq, Hash)] @@ -9,8 +11,8 @@ pub enum ScalarProjection { Compound(Vec), } -impl std::fmt::Debug for ScalarProjection { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for ScalarProjection { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::Single(sf) => f.debug_tuple("SingleProjection").field(&format!("{sf}")).finish(), Self::Compound(sfs) => { diff --git a/query-engine/query-structure/src/internal_data_model.rs b/query-engine/query-structure/src/internal_data_model.rs index 35f0fecc9038..4b4acb6f874f 100644 --- a/query-engine/query-structure/src/internal_data_model.rs +++ b/query-engine/query-structure/src/internal_data_model.rs @@ -1,6 +1,6 @@ use crate::{CompositeType, InternalEnum, prelude::*}; +use alloc::{string::ToString, sync::Arc}; use psl::parser_database as db; -use std::sync::Arc; pub(crate) type InternalDataModelRef = InternalDataModel; diff --git a/query-engine/query-structure/src/internal_enum.rs b/query-engine/query-structure/src/internal_enum.rs index 13dfd7206dca..d277126d667c 100644 --- a/query-engine/query-structure/src/internal_enum.rs +++ b/query-engine/query-structure/src/internal_enum.rs @@ -18,8 +18,8 @@ impl InternalEnum { } } -impl std::fmt::Debug for InternalEnum { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for InternalEnum { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_tuple("InternalEnum").field(&self.name()).finish() } } diff --git a/query-engine/query-structure/src/lib.rs b/query-engine/query-structure/src/lib.rs index 66c4af906dc2..99346da46138 100644 --- a/query-engine/query-structure/src/lib.rs +++ b/query-engine/query-structure/src/lib.rs @@ -1,3 +1,8 @@ +#![no_std] + +#[macro_use] +extern crate alloc; + mod aggregate_selection; mod composite_type; mod convert; @@ -54,4 +59,4 @@ pub use psl::{ schema_ast::ast::{self, FieldArity}, }; -pub type Result = std::result::Result; +pub type Result = core::result::Result; diff --git a/query-engine/query-structure/src/model.rs b/query-engine/query-structure/src/model.rs index 451797c57097..8242f62e9a2b 100644 --- a/query-engine/query-structure/src/model.rs +++ b/query-engine/query-structure/src/model.rs @@ -92,8 +92,8 @@ impl Model { } } -impl std::fmt::Debug for Model { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Model { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_tuple("Model").field(&self.name()).finish() } } diff --git a/query-engine/query-structure/src/native_type_instance.rs b/query-engine/query-structure/src/native_type_instance.rs index 1c69510bcc5d..d341ea060aa3 100644 --- a/query-engine/query-structure/src/native_type_instance.rs +++ b/query-engine/query-structure/src/native_type_instance.rs @@ -1,3 +1,4 @@ +use alloc::{string::String, vec::Vec}; use psl::datamodel_connector::{Connector, NativeTypeInstance as PslNativeTypeInstance}; /// Represents an instance of a native type declared in the Prisma schema. @@ -12,7 +13,7 @@ impl NativeTypeInstance { NativeTypeInstance { native_type, connector } } - pub fn deserialize_native_type(&self) -> &T { + pub fn deserialize_native_type(&self) -> &T { self.native_type.downcast_ref() } diff --git a/query-engine/query-structure/src/order_by.rs b/query-engine/query-structure/src/order_by.rs index 37de5ba16cd3..d735491f347f 100644 --- a/query-engine/query-structure/src/order_by.rs +++ b/query-engine/query-structure/src/order_by.rs @@ -1,5 +1,7 @@ +use alloc::{string::String, vec::Vec}; + use crate::{CompositeFieldRef, RelationFieldRef, ScalarFieldRef}; -use std::fmt::Display; +use core::fmt::Display; #[derive(Clone, Copy, PartialEq, Debug, Eq, Hash)] pub enum SortOrder { @@ -121,8 +123,8 @@ pub enum OrderByHop { Composite(CompositeFieldRef), } -impl std::fmt::Debug for OrderByHop { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for OrderByHop { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::Relation(rf) => f.debug_tuple("Relation").field(&format!("{rf}")).finish(), Self::Composite(cf) => f.debug_tuple("Composite").field(&format!("{cf}")).finish(), @@ -211,7 +213,7 @@ pub struct OrderByRelevance { } impl Display for SortOrder { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { SortOrder::Ascending => f.write_str("ASC"), SortOrder::Descending => f.write_str("DESC"), diff --git a/query-engine/query-structure/src/parent_container.rs b/query-engine/query-structure/src/parent_container.rs index e1ada0875f97..a459a0a77a2a 100644 --- a/query-engine/query-structure/src/parent_container.rs +++ b/query-engine/query-structure/src/parent_container.rs @@ -1,6 +1,10 @@ +use alloc::{borrow::ToOwned, string::String, vec::Vec}; +use core::{ + fmt::Debug, + hash::{Hash, Hasher}, +}; + use crate::{CompositeType, Field, InternalDataModelRef, Model}; -use std::fmt::Debug; -use std::hash::{Hash, Hasher}; #[derive(Clone)] pub enum ParentContainer { @@ -80,7 +84,7 @@ impl From for ParentContainer { } impl Debug for ParentContainer { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { ParentContainer::Model(m) => f .debug_struct("ParentContainer") diff --git a/query-engine/query-structure/src/prisma_value_ext.rs b/query-engine/query-structure/src/prisma_value_ext.rs index b31812bc6139..a77fd2e508da 100644 --- a/query-engine/query-structure/src/prisma_value_ext.rs +++ b/query-engine/query-structure/src/prisma_value_ext.rs @@ -1,5 +1,6 @@ use super::{PrismaValue, Type, TypeIdentifier}; use crate::DomainError; +use alloc::{string::ToString, vec::Vec}; use bigdecimal::ToPrimitive; use prisma_value::{Placeholder, PrismaValueType}; diff --git a/query-engine/query-structure/src/projections/model_projection.rs b/query-engine/query-structure/src/projections/model_projection.rs index de9a689cac34..8c4cc9a09ebb 100644 --- a/query-engine/query-structure/src/projections/model_projection.rs +++ b/query-engine/query-structure/src/projections/model_projection.rs @@ -1,4 +1,5 @@ use crate::{Field, FieldSelection, ScalarFieldRef, SelectedField, TypeIdentifier}; +use alloc::{borrow::ToOwned, string::String, vec::Vec}; use itertools::Itertools; use psl::schema_ast::ast::FieldArity; @@ -99,7 +100,7 @@ impl ModelProjection { impl IntoIterator for ModelProjection { type Item = Field; - type IntoIter = std::vec::IntoIter; + type IntoIter = alloc::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { self.fields.into_iter() diff --git a/query-engine/query-structure/src/query_arguments.rs b/query-engine/query-structure/src/query_arguments.rs index 79951fdc7413..c09cda732d73 100644 --- a/query-engine/query-structure/src/query_arguments.rs +++ b/query-engine/query-structure/src/query_arguments.rs @@ -1,3 +1,4 @@ +use alloc::{borrow::ToOwned, vec::Vec}; use psl::{PreviewFeature, datamodel_connector::ConnectorCapability, has_capability}; use crate::*; @@ -103,8 +104,8 @@ impl TryFrom<&str> for RelationLoadStrategy { } } -impl std::fmt::Debug for QueryArguments { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for QueryArguments { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("QueryArguments") .field("model", &self.model.name()) .field("cursor", &self.cursor) diff --git a/query-engine/query-structure/src/record.rs b/query-engine/query-structure/src/record.rs index cfa527d9f9bf..1a6585c8f44a 100644 --- a/query-engine/query-structure/src/record.rs +++ b/query-engine/query-structure/src/record.rs @@ -1,8 +1,12 @@ use crate::{ DomainError, FieldSelection, ModelProjection, OrderBy, PrismaValue, SelectedField, SelectionResult, SortOrder, }; +use alloc::{ + string::{String, ToString}, + vec::Vec, +}; +use hashbrown::HashMap; use itertools::Itertools; -use std::collections::HashMap; #[derive(Debug, Clone)] pub struct SingleRecord { diff --git a/query-engine/query-structure/src/relation.rs b/query-engine/query-structure/src/relation.rs index b85869f001b0..e049c99e5c5b 100644 --- a/query-engine/query-structure/src/relation.rs +++ b/query-engine/query-structure/src/relation.rs @@ -1,3 +1,4 @@ +use alloc::string::{String, ToString}; use psl::{ datamodel_connector::walker_ext_traits::*, parser_database::{ReferentialAction, RelationId, walkers}, @@ -70,8 +71,8 @@ impl Relation { } } -impl std::fmt::Debug for Relation { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Relation { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_tuple("Relation").field(&self.name()).finish() } } diff --git a/query-engine/query-structure/src/selection_result.rs b/query-engine/query-structure/src/selection_result.rs index 8caa68588ccc..f8d9c7b3dd89 100644 --- a/query-engine/query-structure/src/selection_result.rs +++ b/query-engine/query-structure/src/selection_result.rs @@ -1,6 +1,6 @@ use crate::{DomainError, FieldSelection, PrismaValue, ScalarFieldRef, SelectedField}; +use alloc::{borrow::Cow, vec::Vec}; use itertools::Itertools; -use std::{borrow::Cow, convert::TryFrom}; /// Represents a set of results. #[derive(Default, Clone, PartialEq, Eq, Hash)] @@ -8,8 +8,8 @@ pub struct SelectionResult { pub pairs: Vec<(SelectedField, PrismaValue)>, } -impl std::fmt::Debug for SelectionResult { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for SelectionResult { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_list() .entries( self.pairs @@ -164,7 +164,7 @@ impl TryFrom for PrismaValue { impl IntoIterator for SelectionResult { type Item = (SelectedField, PrismaValue); - type IntoIter = std::vec::IntoIter; + type IntoIter = alloc::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { self.pairs.into_iter() diff --git a/query-engine/query-structure/src/write_args.rs b/query-engine/query-structure/src/write_args.rs index 1dde6a10ee9c..3ec24005946d 100644 --- a/query-engine/query-structure/src/write_args.rs +++ b/query-engine/query-structure/src/write_args.rs @@ -1,9 +1,11 @@ +use core::{borrow::Borrow, ops::Deref}; + use crate::{ CompositeFieldRef, Field, Filter, Model, ModelProjection, PrismaValue, ScalarFieldRef, SelectedField, SelectionResult, }; +use alloc::{borrow::ToOwned, boxed::Box, string::String, vec::Vec}; use indexmap::{IndexMap, map::Keys}; -use std::{borrow::Borrow, convert::TryInto, ops::Deref}; /// WriteArgs represent data to be written to an underlying data source. #[derive(Debug, PartialEq, Clone)] diff --git a/query-engine/query-structure/src/zipper.rs b/query-engine/query-structure/src/zipper.rs index 2aec587494f3..c1b9c4699cb2 100644 --- a/query-engine/query-structure/src/zipper.rs +++ b/query-engine/query-structure/src/zipper.rs @@ -1,5 +1,5 @@ use crate::{InternalDataModelRef, psl::parser_database::walkers::Walker}; -use std::hash::{Hash, Hasher}; +use core::hash::{Hash, Hasher}; // Invariant: InternalDataModel must not contain any Zipper, this would be a reference counting // cycle (memory leak). @@ -19,13 +19,13 @@ impl PartialEq for Zipper { impl Eq for Zipper {} impl PartialOrd for Zipper { - fn partial_cmp(&self, other: &Self) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { self.id.partial_cmp(&other.id) } } impl Ord for Zipper { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { self.id.cmp(&other.id) } } diff --git a/query-engine/schema/Cargo.toml b/query-engine/schema/Cargo.toml index 82d167a0568b..165f6b0fa010 100644 --- a/query-engine/schema/Cargo.toml +++ b/query-engine/schema/Cargo.toml @@ -6,7 +6,6 @@ edition.workspace = true [dependencies] query-structure.workspace = true psl.workspace = true -rustc-hash.workspace = true [dev-dependencies] codspeed-criterion-compat.workspace = true