Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starlark alloc alignment assertions fail following rustc 1.72 TypeId changes #408

Closed
cormacrelf opened this issue Sep 6, 2023 · 4 comments

Comments

@cormacrelf
Copy link
Contributor

cormacrelf commented Sep 6, 2023

Latest builds are red, bisecting reveals 21381685c as the source. Weirdly only macos seems to be affected.

See rust-lang/rust#109953, which I am pretty sure this is related to. The alloc is now aligned to 16 bytes with no code changes. Compare the changelog https://releases.rs/docs/1.72.0/

I should mention this seems to happen when you run any command that evaluates starlark.

Backtrace showing the assertion failure
nightly-2023-06-27 thread 'buck2-rt' panicked at 'Unexpected alignment in Starlark arena. Type starlark::values::layout::avalue::AValueImpl<starlark::values::layout::avalue::Simple, starlark::values::typing::type_compiled::compiled::TypeCompiledImplAsStarlarkValue<starlark::values::typing::type_compiled::matchers::StarlarkTypeIdMatcher>> has alignment 16, expected <= 8', starlark-rust/starlark/src/values/layout/heap/arena.rs:174:9
stack backtrace:
thread 'buck2-rt' panicked at 'Unexpected alignment in Starlark arena. Type starlark::values::layout::avalue::AValueImpl<starlark::values::layout::avalue::Simple, starlark::values::typing::type_compiled::compiled::TypeCompiledImplAsStarlarkValue<starlark::values::typing::type_compiled::matchers::StarlarkTypeIdMatcher>> has alignment 16, expected <= 8', starlark-rust/starlark/src/values/layout/heap/arena.rs:174:9
thread 'buck2-rt' panicked at 'Unexpected alignment in Starlark arena. Type starlark::values::layout::avalue::AValueImpl<starlark::values::layout::avalue::Simple, starlark::values::typing::type_compiled::compiled::TypeCompiledImplAsStarlarkValue<starlark::values::typing::type_compiled::matchers::StarlarkTypeIdMatcher>> has alignment 16, expected <= 8', starlark-rust/starlark/src/values/layout/heap/arena.rs:174:9
thread 'buck2-rt' panicked at 'Unexpected alignment in Starlark arena. Type starlark::values::layout::avalue::AValueImpl<starlark::values::layout::avalue::Simple, starlark::values::typing::type_compiled::compiled::TypeCompiledImplAsStarlarkValue<starlark::values::typing::type_compiled::matchers::StarlarkTypeIdMatcher>> has alignment 16, expected <= 8', starlark-rust/starlark/src/values/layout/heap/arena.rs:174:9
thread 'buck2-rt' panicked at 'Unexpected alignment in Starlark arena. Type starlark::values::layout::avalue::AValueImpl<starlark::values::layout::avalue::Simple, starlark::values::typing::type_compiled::compiled::TypeCompiledImplAsStarlarkValue<starlark::values::typing::type_compiled::matchers::StarlarkTypeIdMatcher>> has alignment 16, expected <= 8', thread 'buck2-rt' panicked at 'Unexpected alignment in Starlark arena. Type starlark::values::layout::avalue::AValueImpl<starlark::values::layout::avalue::Simple, starlark::values::typing::type_compiled::compiled::TypeCompiledImplAsStarlarkValue<starlark::values::typing::type_compiled::matchers::IsAnyOfTwo<starlark::values::typing::type_compiled::matchers::IsNone, starlark::values::typing::type_compiled::matchers::StarlarkTypeIdMatcher>>> has alignment 16, expected <= 8', starlark-rust/starlark/src/values/layout/heap/arena.rs:174:9
starlark-rust/starlark/src/values/layout/heap/arena.rs:174:9
thread 'buck2-rt' panicked at 'Unexpected alignment in Starlark arena. Type starlark::values::layout::avalue::AValueImpl<starlark::values::layout::avalue::Simple, starlark::values::typing::type_compiled::compiled::TypeCompiledImplAsStarlarkValue<starlark::values::typing::type_compiled::matchers::StarlarkTypeIdMatcher>> has alignment 16, expected <= 8', starlark-rust/starlark/src/values/layout/heap/arena.rs:174:9
thread 'buck2-rt' panicked at 'Unexpected alignment in Starlark arena. Type starlark::values::layout::avalue::AValueImpl<starlark::values::layout::avalue::Simple, starlark::values::typing::type_compiled::compiled::TypeCompiledImplAsStarlarkValue<starlark::values::typing::type_compiled::matchers::StarlarkTypeIdMatcher>> has alignment 16, expected <= 8', starlark-rust/starlark/src/values/layout/heap/arena.rs:174:9
   0: rust_begin_unwind
             at /rustc/36fb58e433c782e27dd41034284e157cf86d587f/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at /rustc/36fb58e433c782e27dd41034284e157cf86d587f/library/core/src/panicking.rs:67:14
   2: starlark::values::layout::heap::arena::Arena<A>::alloc_uninit
             at /Users/me/src/buck2/starlark-rust/starlark/src/values/layout/heap/arena.rs:174:9
   3: starlark::values::layout::heap::arena::Arena<A>::alloc
             at /Users/me/src/buck2/starlark-rust/starlark/src/values/layout/heap/arena.rs:249:26
   4: starlark::values::layout::heap::heap_type::Heap::alloc_raw
             at /Users/me/src/buck2/starlark-rust/starlark/src/values/layout/heap/heap_type.rs:592:33
   5: starlark::values::layout::heap::heap_type::Heap::alloc_simple
             at /Users/me/src/buck2/starlark-rust/starlark/src/values/layout/heap/heap_type.rs:761:9
   6: starlark::values::typing::type_compiled::compiled::TypeCompiled<starlark::values::layout::value::Value>::alloc
             at /Users/me/src/buck2/starlark-rust/starlark/src/values/typing/type_compiled/compiled.rs:378:22
   7: <starlark::values::typing::type_compiled::factory::TypeCompiledFactory as starlark::values::typing::type_compiled::alloc::TypeMatcherAlloc>::alloc
             at /Users/me/src/buck2/starlark-rust/starlark/src/values/typing/type_compiled/factory.rs:47:9
   8: starlark::values::typing::type_compiled::compiled::TypeCompiled<starlark::values::layout::value::Value>::from_ty
             at /Users/me/src/buck2/starlark-rust/starlark/src/values/typing/type_compiled/compiled.rs:435:9
   9: starlark::values::typing::type_compiled::compiled::TypeCompiled<starlark::values::layout::value::Value>::new
             at /Users/me/src/buck2/starlark-rust/starlark/src/values/typing/type_compiled/compiled.rs:455:16
  10: starlark::eval::compiler::types::<impl starlark::eval::compiler::Compiler>::alloc_value_for_type
             at /Users/me/src/buck2/starlark-rust/starlark/src/eval/compiler/types.rs:102:18
  11: starlark::eval::compiler::types::<impl starlark::eval::compiler::Compiler>::eval_path_as_type
             at /Users/me/src/buck2/starlark-rust/starlark/src/eval/compiler/types.rs:151:9
  12: starlark::eval::compiler::types::<impl starlark::eval::compiler::Compiler>::eval_expr_as_type
             at /Users/me/src/buck2/starlark-rust/starlark/src/eval/compiler/types.rs:159:50
  13: starlark::eval::compiler::types::<impl starlark::eval::compiler::Compiler>::populate_types_in_type_expr
             at /Users/me/src/buck2/starlark-rust/starlark/src/eval/compiler/types.rs:245:26
  14: starlark::eval::compiler::types::<impl starlark::eval::compiler::Compiler>::populate_types_in_stmt::{{closure}}
             at /Users/me/src/buck2/starlark-rust/starlark/src/eval/compiler/types.rs:254:55
  15: starlark_syntax::syntax::uniplate::<impl starlark_syntax::syntax::ast::StmtP<P>>::visit_type_expr_err_mut
             at /Users/me/src/buck2/starlark-rust/starlark_syntax/src/syntax/uniplate.rs:287:25
  16: starlark::eval::compiler::types::<impl starlark::eval::compiler::Compiler>::populate_types_in_stmt
             at /Users/me/src/buck2/starlark-rust/starlark/src/eval/compiler/types.rs:254:9
  17: starlark::eval::compiler::module::<impl starlark::eval::compiler::Compiler>::eval_top_level_stmt
             at /Users/me/src/buck2/starlark-rust/starlark/src/eval/compiler/module.rs:150:13
  18: starlark::eval::compiler::module::<impl starlark::eval::compiler::Compiler>::eval_module
             at /Users/me/src/buck2/starlark-rust/starlark/src/eval/compiler/module.rs:219:21
  19: starlark::eval::<impl starlark::eval::runtime::evaluator::Evaluator>::eval_module
             at /Users/me/src/buck2/starlark-rust/starlark/src/eval/mod.rs:136:19
  20: buck2_interpreter_for_build::interpreter::interpreter_for_cell::InterpreterForCell::eval
             at /Users/me/src/buck2/app/buck2_interpreter_for_build/src/interpreter/interpreter_for_cell.rs:469:19
  21: buck2_interpreter_for_build::interpreter::interpreter_for_cell::InterpreterForCell::eval_module
             at /Users/me/src/buck2/app/buck2_interpreter_for_build/src/interpreter/interpreter_for_cell.rs:510:9
  22: buck2_interpreter_for_build::interpreter::dice_calculation_delegate::DiceCalculationDelegate::eval_module_uncached::{{closure}}::{{closure}}
             at /Users/me/src/buck2/app/buck2_interpreter_for_build/src/interpreter/dice_calculation_delegate.rs:271:34
  23: buck2_interpreter::dice::starlark_provider::with_starlark_eval_provider::{{closure}}
             at /Users/me/src/buck2/app/buck2_interpreter/src/dice/starlark_provider.rs:96:13
  24: buck2_interpreter_for_build::interpreter::dice_calculation_delegate::DiceCalculationDelegate::eval_module_uncached::{{closure}}
             at /Users/me/src/buck2/app/buck2_interpreter_for_build/src/interpreter/dice_calculation_delegate.rs:292:10
  25: buck2_interpreter_for_build::interpreter::dice_calculation_delegate::DiceCalculationDelegate::eval_module::{{closure}}::<impl dice::api::key::Key for buck2_interpreter_for_build::interpreter::dice_calculation_delegate::keys::EvalImportKey>::compute::{{closure}}
             at /Users/me/src/buck2/app/buck2_interpreter_for_build/src/interpreter/dice_calculation_delegate.rs:175:22
  26: dice::legacy::<impl dice::legacy::incremental::evaluator::Evaluator for dice::legacy::key::StoragePropertiesForKey<K>>::eval::{{closure}}
             at /Users/me/src/buck2/dice/dice/src/legacy/mod.rs:280:14
  27: dice::legacy::incremental::IncrementalEngine<K>::compute::{{closure}}::{{closure}}
             at /Users/me/src/buck2/dice/dice/src/legacy/incremental/mod.rs:579:14
  28: dice::legacy::incremental::IncrementalEngine<K>::compute::{{closure}}
             at /Users/me/src/buck2/dice/dice/src/legacy/incremental/mod.rs:542:5
  29: dice::legacy::incremental::IncrementalEngine<K>::new_dice_task::{{closure}}
             at /Users/me/src/buck2/dice/dice/src/legacy/incremental/mod.rs:488:26
  30: more_futures::cancellable_future::CancellableFutureProj<F>::poll_inner
             at /Users/me/src/buck2/shed/more_futures/src/cancellable_future.rs:257:13
  31: <more_futures::cancellable_future::CancellableFuture<F> as core::future::future::Future>::poll
             at /Users/me/src/buck2/shed/more_futures/src/cancellable_future.rs:300:20
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
Build ID: 8ee76dad-1ad3-440b-8327-fbd8d471fc36
Jobs completed: 143. Time elapsed: 0.3s.
Command failed: Buck daemon event bus encountered an error, the root cause (if available) is displayed above this message.

Caused by:
    0: status: Unknown, message: "h2 protocol error: error reading a body from connection: stream closed because of a broken pipe", details: [], metadata: MetadataMap { headers: {} }
    1: error reading a body from connection: stream closed because of a broken pipe
    2: stream closed because of a broken pipe
@cormacrelf cormacrelf changed the title Starlark alloc alignment assersions fail following rustc 1.72 TypeId changes Starlark alloc alignment assertions fail following rustc 1.72 TypeId changes Sep 6, 2023
@ndmitchell
Copy link
Contributor

Thanks for the report! We'll take a look. Kind of surprised our internal CI didn't bleat loudly at this,

@stepancheg
Copy link
Contributor

stepancheg commented Sep 6, 2023

Edit: nevermind, I can reproduce it.

@stepancheg
Copy link
Contributor

stepancheg commented Sep 6, 2023

Kind of surprised our internal CI didn't bleat loudly at this

u128 is has alignment 8 on x86_64, but 16 on Apple Silicon.

@stepancheg
Copy link
Contributor

Internal: should be fixed in D49019964.

facebook-github-bot pushed a commit to facebook/starlark-rust that referenced this issue Sep 6, 2023
Summary:
* `TypeId` is `u128` [in Rust 1.72](rust-lang/rust#109953)
* `u128` is 16 bytes aligned on Apple Silicon
* we require 8 byte alignment for `StarlarkValue`

Maybe we should fix heap allocations: insert padding to allow any alignment.

But practically we don't need it and should not do it: generated machine code is identical for aligned and 8-byte aligned `u128`: [compiler explorer](https://rust.godbolt.org/z/96KsnjW77) (note it is identical if we load it from memory not pass by value, but this is what we do).

So for now just force 8 byte alignment on `TypeId`.

Fixes issue facebook/buck2#408

Reviewed By: ndmitchell, shayne-fletcher

Differential Revision: D49019964

fbshipit-source-id: 62c8d7db83e9e4bdbe58fe7a62d5daae41996e61
facebook-github-bot pushed a commit that referenced this issue Sep 6, 2023
Summary:
* `TypeId` is `u128` [in Rust 1.72](rust-lang/rust#109953)
* `u128` is 16 bytes aligned on Apple Silicon
* we require 8 byte alignment for `StarlarkValue`

Maybe we should fix heap allocations: insert padding to allow any alignment.

But practically we don't need it and should not do it: generated machine code is identical for aligned and 8-byte aligned `u128`: [compiler explorer](https://rust.godbolt.org/z/96KsnjW77) (note it is identical if we load it from memory not pass by value, but this is what we do).

So for now just force 8 byte alignment on `TypeId`.

Fixes issue #408

Reviewed By: ndmitchell, shayne-fletcher

Differential Revision: D49019964

fbshipit-source-id: 62c8d7db83e9e4bdbe58fe7a62d5daae41996e61
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants