Starlark update throws errors related to the Allocative trait.
hulto opened this issue Β· comments
I'm working on updating to the latest version of starlark (acf6384) on the main branch so I can leverage the PrintHandle
attribute and set a custom handler.
I was having some issues around allocative so I tried just building one of the example code sections but ran into the same compiler error.
https://github.com/facebookexperimental/starlark-rust/blob/acf638430a00ca3855862e8c669670e1adaa42aa/starlark/src/lib.rs#L287
I made some minor modifications like moving the struct definition and impl's out of the run function.
#![feature(trivial_bounds)]
use starlark::environment::{Globals, Module};
use starlark::eval::Evaluator;
use starlark::syntax::{AstModule, Dialect};
use starlark::values::{Heap, StarlarkValue, Value, ValueError, ValueLike, ProvidesStaticType, NoSerialize};
use starlark::{starlark_type, starlark_simple_value};
use std::fmt::{self, Display, Write};
use allocative::Allocative;
// Define complex numbers
#[derive(Debug, PartialEq, Eq, ProvidesStaticType, Allocative, NoSerialize)]
struct Complex {
real: i32,
imaginary: i32,
}
starlark_simple_value!(Complex);
impl Display for Complex {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} + {}i", self.real, self.imaginary)
}
}
impl<'v> StarlarkValue<'v> for Complex {
starlark_type!("complex");
// How we add them
fn add(&self, rhs: Value<'v>, heap: &'v Heap)
-> Option<anyhow::Result<Value<'v>>> {
if let Some(rhs) = rhs.downcast_ref::<Self>() {
Some(Ok(heap.alloc(Complex {
real: self.real + rhs.real,
imaginary: self.imaginary + rhs.imaginary,
})))
} else {
None
}
}
}
fn run() -> anyhow::Result<()> {
let content = "str(a + b)";
let ast = AstModule::parse("complex.star", content.to_owned(), &Dialect::Standard)?;
let globals = Globals::standard();
let module = Module::new();
// We inject some complex numbers into the module before we start.
let a = module.heap().alloc(Complex {real: 1, imaginary: 8});
module.set("a", a);
let b = module.heap().alloc(Complex {real: 4, imaginary: 2});
module.set("b", b);
let mut eval = Evaluator::new(&module);
let res = eval.eval_module(ast, &globals)?;
assert_eq!(res.unpack_str(), Some("5 + 10i"));
Ok(())
}
fn main(){ run().unwrap(); }
When building the project I get an error that the Allocative
trait is not implemented for the Complex
struct.
Downloads/starlark-test/starlark-test-proj ξ° π¦ 1.70.0-nightly ξ° ξ master β β ξ°
$ cargo run
Compiling rustix v0.36.11
Compiling terminal_size v0.2.5
Compiling clap_builder v4.2.1
Compiling clap v4.2.1
Compiling starlark v0.9.0-pre (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843)
Compiling starlark-test-proj v0.1.0 (/Users/hulto/Downloads/starlark-test/starlark-test-proj)
warning: unused import: `ValueError`
--> src/main.rs:6:52
|
6 | use starlark::values::{Heap, StarlarkValue, Value, ValueError, ValueLike, ProvidesStaticType, NoSerialize};
| ^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error[E0277]: the trait bound `Complex: allocative::allocative_trait::Allocative` is not satisfied
--> src/main.rs:25:32
|
25 | impl<'v> StarlarkValue<'v> for Complex {
| ^^^^^^^ the trait `allocative::allocative_trait::Allocative` is not implemented for `Complex`
|
= help: the following other types implement trait `allocative::allocative_trait::Allocative`:
!
&'static T
()
(A, B)
(A, B, C)
(A, B, C, D)
(A, B, C, D, E)
(A,)
and 118 others
note: required by a bound in `StarlarkValue`
--> /Users/hulto/.cargo/git/checkouts/starlark-rust-59575ffdf833204c/acf6384/starlark/src/values/traits.rs:206:31
|
206 | 'v + ProvidesStaticType + Allocative + Debug + Display + Serialize + Sized
| ^^^^^^^^^^ required by this bound in `StarlarkValue`
For more information about this error, try `rustc --explain E0277`.
warning: `starlark-test-proj` (bin "starlark-test-proj") generated 1 warning
error: could not compile `starlark-test-proj` (bin "starlark-test-proj") due to previous error; 1 warning emitted
I tried implementing the Allocative trait manually instead of through a derive but got the same error.
Doing both, defining the Allocative trait manuallly and through derive throws an error that Allocative
is defined twice.
cargo version
cargo 1.70.0-nightly (145219a9f 2023-03-27)
Cargo.toml
[dependencies]
starlark = { git = "https://github.com/facebookexperimental/starlark-rust", rev = "acf638430a00ca3855862e8c669670e1adaa42aa" }
allocative = { version = "0.2" }
allocative_derive = { version = "0.2" }
anyhow = "1.0.65"
Just derive(Allocative)
should be sufficient.
Check cargo tree
please, do you have the same version of allocative
in starlark
dependency and in your crate dependency?
I think the versions in my crate & Starlark are the same.
I'm not vendoring the allocative crate though.
starlark-test-proj v0.1.0 (/Users/hulto/Downloads/starlark-test/starlark-test-proj)
βββ allocative v0.2.0
β βββ allocative_derive v0.2.0 (proc-macro)
β βββ proc-macro2 v1.0.54
β β βββ unicode-ident v1.0.8
β βββ quote v1.0.26
β β βββ proc-macro2 v1.0.54 (*)
β βββ syn v1.0.109
β βββ proc-macro2 v1.0.54 (*)
β βββ quote v1.0.26 (*)
β βββ unicode-ident v1.0.8
βββ allocative_derive v0.2.0 (proc-macro) (*)
βββ anyhow v1.0.70
βββ starlark v0.9.0-pre (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843)
βββ allocative v0.2.0 (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843)
β βββ allocative_derive v0.2.0 (proc-macro) (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843)
β β βββ proc-macro2 v1.0.54 (*)
β β βββ quote v1.0.26 (*)
β β βββ syn v1.0.109 (*)
β βββ bumpalo v3.12.0
β βββ ctor v0.1.26 (proc-macro)
β β βββ quote v1.0.26 (*)
β β βββ syn v1.0.109 (*)
β βββ hashbrown v0.12.3
β β βββ ahash v0.7.6
β β βββ getrandom v0.2.8
β β β βββ cfg-if v1.0.0
β β β βββ libc v0.2.140
β β βββ once_cell v1.17.1
β β [build-dependencies]
β β βββ version_check v0.9.4
β βββ num-bigint v0.4.3
β βββ num-integer v0.1.45
β β βββ num-traits v0.2.15
β β [build-dependencies]
β β βββ autocfg v1.1.0
β β [build-dependencies]
β β βββ autocfg v1.1.0
β βββ num-traits v0.2.15 (*)
β [build-dependencies]
β βββ autocfg v1.1.0
βββ annotate-snippets v0.9.1
β βββ unicode-width v0.1.10
βββ anyhow v1.0.70
βββ argfile v0.1.5
β βββ os_str_bytes v6.5.0
β βββ memchr v2.5.0
βββ bumpalo v3.12.0
βββ clap v4.2.1
β βββ clap_builder v4.2.1
β β βββ anstream v0.2.6
β β β βββ anstyle v0.3.5
β β β βββ anstyle-parse v0.1.1
β β β β βββ utf8parse v0.2.1
β β β βββ concolor-override v1.0.0
β β β βββ concolor-query v0.3.3
β β β βββ is-terminal v0.4.6
β β β β βββ io-lifetimes v1.0.9
β β β β β βββ libc v0.2.140
β β β β βββ rustix v0.37.5
β β β β βββ bitflags v1.3.2
β β β β βββ errno v0.3.0
β β β β β βββ libc v0.2.140
β β β β βββ io-lifetimes v1.0.9 (*)
β β β β βββ libc v0.2.140
β β β βββ utf8parse v0.2.1
β β βββ anstyle v0.3.5
β β βββ bitflags v1.3.2
β β βββ clap_lex v0.4.1
β β βββ strsim v0.10.0
β β βββ terminal_size v0.2.5
β β βββ rustix v0.36.11
β β βββ bitflags v1.3.2
β β βββ errno v0.2.8
β β β βββ libc v0.2.140
β β βββ io-lifetimes v1.0.9 (*)
β β βββ libc v0.2.140
β βββ clap_derive v4.2.0 (proc-macro)
β β βββ heck v0.4.1
β β βββ proc-macro2 v1.0.54 (*)
β β βββ quote v1.0.26 (*)
β β βββ syn v2.0.11
β β βββ proc-macro2 v1.0.54 (*)
β β βββ quote v1.0.26 (*)
β β βββ unicode-ident v1.0.8
β βββ once_cell v1.17.1
βββ debugserver-types v0.5.0
β βββ schemafy v0.5.2 (proc-macro)
β β βββ Inflector v0.11.4
β β β βββ lazy_static v1.4.0
β β β βββ regex v1.7.3
β β β βββ aho-corasick v0.7.20
β β β β βββ memchr v2.5.0
β β β βββ memchr v2.5.0
β β β βββ regex-syntax v0.6.29
β β βββ schemafy_core v0.5.2
β β β βββ serde v1.0.159
β β β β βββ serde_derive v1.0.159 (proc-macro)
β β β β βββ proc-macro2 v1.0.54 (*)
β β β β βββ quote v1.0.26 (*)
β β β β βββ syn v2.0.11 (*)
β β β βββ serde_json v1.0.95
β β β βββ itoa v1.0.6
β β β βββ ryu v1.0.13
β β β βββ serde v1.0.159 (*)
β β βββ schemafy_lib v0.5.2
β β β βββ Inflector v0.11.4 (*)
β β β βββ proc-macro2 v1.0.54 (*)
β β β βββ quote v1.0.26 (*)
β β β βββ schemafy_core v0.5.2 (*)
β β β βββ serde v1.0.159 (*)
β β β βββ serde_derive v1.0.159 (proc-macro) (*)
β β β βββ serde_json v1.0.95 (*)
β β β βββ syn v1.0.109 (*)
β β βββ serde v1.0.159 (*)
β β βββ serde_derive v1.0.159 (proc-macro) (*)
β β βββ serde_json v1.0.95 (*)
β β βββ serde_repr v0.1.12 (proc-macro)
β β β βββ proc-macro2 v1.0.54 (*)
β β β βββ quote v1.0.26 (*)
β β β βββ syn v2.0.11 (*)
β β βββ syn v1.0.109 (*)
β βββ serde v1.0.159 (*)
β βββ serde_json v1.0.95 (*)
βββ derivative v2.2.0 (proc-macro)
β βββ proc-macro2 v1.0.54 (*)
β βββ quote v1.0.26 (*)
β βββ syn v1.0.109 (*)
βββ derive_more v0.99.17 (proc-macro)
β βββ convert_case v0.4.0
β βββ proc-macro2 v1.0.54 (*)
β βββ quote v1.0.26 (*)
β βββ syn v1.0.109 (*)
β [build-dependencies]
β βββ rustc_version v0.4.0
β βββ semver v1.0.17
βββ dupe v0.8.1 (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843)
β βββ dupe_derive v0.8.0 (proc-macro) (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843)
β βββ proc-macro2 v1.0.54 (*)
β βββ quote v1.0.26 (*)
β βββ syn v1.0.109 (*)
βββ either v1.8.1
βββ erased-serde v0.3.25
β βββ serde v1.0.159 (*)
βββ fancy-regex v0.10.0
β βββ bit-set v0.5.3
β β βββ bit-vec v0.6.3
β βββ regex v1.7.3 (*)
βββ gazebo v0.8.1 (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843)
β βββ dupe v0.8.1 (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843) (*)
β βββ gazebo_derive v0.8.0 (proc-macro) (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843)
β βββ proc-macro2 v1.0.54 (*)
β βββ quote v1.0.26 (*)
β βββ syn v1.0.109 (*)
βββ hashbrown v0.12.3 (*)
βββ inventory v0.1.11
β βββ ctor v0.1.26 (proc-macro) (*)
β βββ ghost v0.1.9 (proc-macro)
β β βββ proc-macro2 v1.0.54 (*)
β β βββ quote v1.0.26 (*)
β β βββ syn v2.0.11 (*)
β βββ inventory-impl v0.1.11 (proc-macro)
β βββ proc-macro2 v1.0.54 (*)
β βββ quote v1.0.26 (*)
β βββ syn v1.0.109 (*)
βββ itertools v0.10.5
β βββ either v1.8.1
βββ lalrpop-util v0.19.9
βββ logos v0.12.1
β βββ logos-derive v0.12.1 (proc-macro)
β βββ beef v0.5.2
β βββ fnv v1.0.7
β βββ proc-macro2 v1.0.54 (*)
β βββ quote v1.0.26 (*)
β βββ regex-syntax v0.6.29
β βββ syn v1.0.109 (*)
βββ lsp-server v0.5.2
β βββ crossbeam-channel v0.5.7
β β βββ cfg-if v1.0.0
β β βββ crossbeam-utils v0.8.15
β β βββ cfg-if v1.0.0
β βββ log v0.4.17
β β βββ cfg-if v1.0.0
β βββ serde v1.0.159 (*)
β βββ serde_json v1.0.95 (*)
βββ lsp-types v0.93.2
β βββ bitflags v1.3.2
β βββ serde v1.0.159 (*)
β βββ serde_json v1.0.95 (*)
β βββ serde_repr v0.1.12 (proc-macro) (*)
β βββ url v2.3.1
β βββ form_urlencoded v1.1.0
β β βββ percent-encoding v2.2.0
β βββ idna v0.3.0
β β βββ unicode-bidi v0.3.13
β β βββ unicode-normalization v0.1.22
β β βββ tinyvec v1.6.0
β β βββ tinyvec_macros v0.1.1
β βββ percent-encoding v2.2.0
β βββ serde v1.0.159 (*)
βββ maplit v1.0.2
βββ memchr v2.5.0
βββ memoffset v0.6.5
β [build-dependencies]
β βββ autocfg v1.1.0
βββ num-bigint v0.4.3 (*)
βββ num-traits v0.2.15 (*)
βββ once_cell v1.17.1
βββ paste v1.0.12 (proc-macro)
βββ regex v1.7.3 (*)
βββ rustyline v7.1.0
β βββ bitflags v1.3.2
β βββ cfg-if v1.0.0
β βββ dirs-next v2.0.0
β β βββ cfg-if v1.0.0
β β βββ dirs-sys-next v0.1.2
β β βββ libc v0.2.140
β βββ fs2 v0.4.3
β β βββ libc v0.2.140
β βββ libc v0.2.140
β βββ log v0.4.17 (*)
β βββ memchr v2.5.0
β βββ nix v0.19.1
β β βββ bitflags v1.3.2
β β βββ cfg-if v1.0.0
β β βββ libc v0.2.140
β βββ unicode-segmentation v1.10.1
β βββ unicode-width v0.1.10
β βββ utf8parse v0.2.1
βββ serde v1.0.159 (*)
βββ serde_json v1.0.95 (*)
βββ starlark_derive v0.9.0-pre (proc-macro) (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843)
β βββ dupe v0.8.1 (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843) (*)
β βββ gazebo v0.8.1 (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843) (*)
β βββ proc-macro2 v1.0.54 (*)
β βββ quote v1.0.26 (*)
β βββ syn v1.0.109 (*)
βββ starlark_map v0.9.0-pre (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843)
β βββ allocative v0.2.0 (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843) (*)
β βββ dupe v0.8.1 (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843) (*)
β βββ fnv v1.0.7
β βββ gazebo v0.8.1 (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843) (*)
β βββ hashbrown v0.12.3 (*)
βββ static_assertions v1.1.0
βββ strsim v0.10.0
βββ textwrap v0.11.0
β βββ unicode-width v0.1.10
βββ thiserror v1.0.40
β βββ thiserror-impl v1.0.40 (proc-macro)
β βββ proc-macro2 v1.0.54 (*)
β βββ quote v1.0.26 (*)
β βββ syn v2.0.11 (*)
βββ walkdir v2.3.3
βββ same-file v1.0.6
[build-dependencies]
βββ lalrpop v0.19.9
βββ ascii-canvas v3.0.0
β βββ term v0.7.0
β βββ dirs-next v2.0.0 (*)
βββ bit-set v0.5.3
β βββ bit-vec v0.6.3
βββ diff v0.1.13
βββ ena v0.14.2
β βββ log v0.4.17 (*)
βββ is-terminal v0.4.6 (*)
βββ itertools v0.10.5
β βββ either v1.8.1
βββ lalrpop-util v0.19.9
β βββ regex v1.7.3 (*)
βββ petgraph v0.6.3
β βββ fixedbitset v0.4.2
β βββ indexmap v1.9.3
β βββ hashbrown v0.12.3
β [build-dependencies]
β βββ autocfg v1.1.0
βββ pico-args v0.4.2
βββ regex v1.7.3 (*)
βββ regex-syntax v0.6.29
βββ string_cache v0.8.7
β βββ new_debug_unreachable v1.0.4
β βββ once_cell v1.17.1
β βββ parking_lot v0.12.1
β β βββ lock_api v0.4.9
β β β βββ scopeguard v1.1.0
β β β [build-dependencies]
β β β βββ autocfg v1.1.0
β β βββ parking_lot_core v0.9.7
β β βββ cfg-if v1.0.0
β β βββ libc v0.2.140
β β βββ smallvec v1.10.0
β βββ phf_shared v0.10.0
β β βββ siphasher v0.3.10
β βββ precomputed-hash v0.1.1
βββ term v0.7.0 (*)
βββ tiny-keccak v2.0.2
β βββ crunchy v0.2.2
βββ unicode-xid v0.2.4
cargo tree
output shows they are not the same: there are two versions: allocative v0.2.0
and allocative v0.2.0 (https://github.com/facebookexperimental/starlark-rust?rev=acf638430a00ca3855862e8c669670e1adaa42aa#acf63843)
.
To fix it, you need to tell Cargo to take allocative from starlark-rust repo.
(Also we should release new starlark-rust).
Ah! Awesome thank you π
Updated cargo file.
Old
[dependencies]
starlark = { git = "https://github.com/facebookexperimental/starlark-rust", rev = "acf638430a00ca3855862e8c669670e1adaa42aa" }
allocative = { version = "0.2" }
allocative_derive = { version = "0.2" }
anyhow = "1.0.65"
New
[dependencies]
starlark = { git = "https://github.com/facebookexperimental/starlark-rust", rev = "acf638430a00ca3855862e8c669670e1adaa42aa" }
allocative = { git = "https://github.com/facebookexperimental/starlark-rust", rev = "acf638430a00ca3855862e8c669670e1adaa42aa" }
allocative_derive = { git = "https://github.com/facebookexperimental/starlark-rust", rev = "acf638430a00ca3855862e8c669670e1adaa42aa" }
anyhow = "1.0.65"