Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,44 @@ jobs:
- os: windows-latest
target: x86_64-pc-windows-msvc
code-target: win32-x64
allocator: mimalloc
pgo: clap-rs/clap@v4.5.36
- os: windows-latest
target: i686-pc-windows-msvc
allocator: mimalloc
pgo: clap-rs/clap@v4.5.36
- os: windows-latest
target: aarch64-pc-windows-msvc
code-target: win32-arm64
allocator: mimalloc
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
# Use a container with glibc 2.28
# Zig is not used because it doesn't work with PGO
container: quay.io/pypa/manylinux_2_28_x86_64
code-target: linux-x64
allocator: system
pgo: clap-rs/clap@v4.5.36
- os: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
container: quay.io/pypa/manylinux_2_28_aarch64
code-target: linux-arm64
allocator: system
pgo: clap-rs/clap@v4.5.36
- os: ubuntu-latest
target: arm-unknown-linux-gnueabihf
zig_target: arm-unknown-linux-gnueabihf.2.28
code-target: linux-armhf
allocator: system
- os: macos-14
target: x86_64-apple-darwin
code-target: darwin-x64
allocator: system
pgo: clap-rs/clap@v4.5.36
- os: macos-14
target: aarch64-apple-darwin
code-target: darwin-arm64
allocator: system
pgo: clap-rs/clap@v4.5.36

name: dist (${{ matrix.target }})
Expand All @@ -67,6 +75,7 @@ jobs:

env:
RA_TARGET: ${{ matrix.target }}
ALLOCATOR_FLAG: ${{ matrix.allocator != 'system' && format('--{0}', matrix.allocator) || '' }}

steps:
- name: Checkout repository
Expand Down Expand Up @@ -102,11 +111,11 @@ jobs:

- name: Dist (plain)
if: ${{ !matrix.zig_target }}
run: cargo xtask dist --client-patch-version ${{ github.run_number }} ${{ matrix.pgo && format('--pgo {0}', matrix.pgo) || ''}}
run: cargo xtask dist --client-patch-version ${{ github.run_number }} ${{ env.ALLOCATOR_FLAG }} ${{ matrix.pgo && format('--pgo {0}', matrix.pgo) || ''}}

- name: Dist (using zigbuild)
if: ${{ matrix.zig_target }}
run: RA_TARGET=${{ matrix.zig_target}} cargo xtask dist --client-patch-version ${{ github.run_number }} --zig ${{ matrix.pgo && format('--pgo {0}', matrix.pgo) || ''}}
run: RA_TARGET=${{ matrix.zig_target}} cargo xtask dist --client-patch-version ${{ github.run_number }} --zig ${{ env.ALLOCATOR_FLAG }} ${{ matrix.pgo && format('--pgo {0}', matrix.pgo) || ''}}

- run: npm ci
working-directory: editors/code
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/expr_store/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub(crate) fn lower_type_ref(
(store, source_map, type_ref)
}

pub(crate) fn lower_generic_params(
pub fn lower_generic_params(
db: &dyn DefDatabase,
module: ModuleId,
def: GenericDefId,
Expand Down
8 changes: 8 additions & 0 deletions crates/hir-ty/src/consteval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
db::{AnonConstId, AnonConstLoc, GeneralConstId, HirDatabase},
display::DisplayTarget,
generics::Generics,
lower::LoweringMode,
mir::{MirEvalError, MirLowerError, pad16},
next_solver::{
Allocation, Const, ConstKind, Consts, DbInterner, DefaultAny, GenericArgs, ParamConst,
Expand Down Expand Up @@ -305,6 +306,7 @@ pub(crate) enum CreateConstError<'db> {
DoesNotResolve,
ConstHasGenerics,
UnderscoreExpr,
AnonConstInterningDisabled,
TypeMismatch {
#[expect(unused, reason = "will need this for diagnostics")]
actual: Ty<'db>,
Expand Down Expand Up @@ -355,6 +357,7 @@ pub(crate) fn create_anon_const<'a, 'db>(
expected_ty: Ty<'db>,
generics: &dyn Fn() -> &'a Generics<'db>,
create_var: Option<&mut dyn FnMut(Span) -> Const<'db>>,
lowering_mode: LoweringMode,
forbid_params_after: Option<u32>,
) -> Result<Const<'db>, CreateConstError<'db>> {
match &store[expr] {
Expand All @@ -374,6 +377,10 @@ pub(crate) fn create_anon_const<'a, 'db>(
konst
}
_ => {
let Some(token) = lowering_mode.allow_tracked_structs() else {
return Err(CreateConstError::AnonConstInterningDisabled);
};

let allow_using_generic_params = forbid_params_after.is_none();
let konst = AnonConstId::new(
interner.db,
Expand All @@ -383,6 +390,7 @@ pub(crate) fn create_anon_const<'a, 'db>(
ty: StoredEarlyBinder::bind(expected_ty.store()),
allow_using_generic_params,
},
token,
);
let args = if allow_using_generic_params {
GenericArgs::identity_for_item(interner, owner.generic_def(interner.db).into())
Expand Down
11 changes: 9 additions & 2 deletions crates/hir-ty/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::{
consteval::ConstEvalError,
dyn_compatibility::DynCompatibilityViolation,
layout::{Layout, LayoutError},
lower::{GenericDefaults, TypeAliasBounds},
lower::{GenericDefaults, TrackedStructToken, TypeAliasBounds},
mir::{BorrowckResult, MirBody, MirLowerError},
next_solver::{
Allocation, Clause, EarlyBinder, GenericArgs, ParamEnv, PolyFnSig, StoredClauses,
Expand Down Expand Up @@ -421,13 +421,20 @@ pub struct AnonConstLoc {
pub(crate) allow_using_generic_params: bool,
}

#[salsa_macros::interned(debug, no_lifetime, revisions = usize::MAX)]
#[salsa_macros::interned(debug, no_lifetime, revisions = usize::MAX, constructor = new_)]
#[derive(PartialOrd, Ord)]
pub struct AnonConstId {
#[returns(ref)]
pub loc: AnonConstLoc,
}

impl AnonConstId {
pub(crate) fn new(db: &dyn DefDatabase, loc: AnonConstLoc, token: TrackedStructToken) -> Self {
_ = token;
AnonConstId::new_(db, loc)
}
}

impl HasModule for AnonConstId {
fn module(&self, db: &dyn DefDatabase) -> ModuleId {
self.loc(db).owner.module(db)
Expand Down
12 changes: 10 additions & 2 deletions crates/hir-ty/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ use crate::{
unify::resolve_completely::WriteBackCtxt,
},
lower::{
ImplTraitIdx, ImplTraitLoweringMode, LifetimeElisionKind, diagnostics::TyLoweringDiagnostic,
ImplTraitIdx, ImplTraitLoweringMode, LifetimeElisionKind, LoweringMode,
diagnostics::TyLoweringDiagnostic,
},
method_resolution::CandidateId,
next_solver::{
Expand All @@ -116,13 +117,14 @@ use cast::{CastCheck, CastError};

/// The entry point of type inference.
fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> InferenceResult {
infer_query_with_inspect(db, def, None)
infer_query_with_inspect(db, def, None, LoweringMode::Analysis)
}

pub fn infer_query_with_inspect<'db>(
db: &'db dyn HirDatabase,
def: DefWithBodyId,
inspect: Option<ObligationInspector<'db>>,
lowering_mode: LoweringMode,
) -> InferenceResult {
let _p = tracing::info_span!("infer_query").entered();
let resolver = def.resolver(db);
Expand All @@ -135,6 +137,7 @@ pub fn infer_query_with_inspect<'db>(
&body.store,
resolver,
true,
lowering_mode,
);

if let Some(inspect) = inspect {
Expand Down Expand Up @@ -202,6 +205,7 @@ fn infer_anon_const_query(db: &dyn HirDatabase, def: AnonConstId) -> InferenceRe
store,
resolver,
loc.allow_using_generic_params,
LoweringMode::Analysis,
);

ctx.infer_expr(
Expand Down Expand Up @@ -1236,6 +1240,7 @@ pub(crate) struct InferenceContext<'body, 'db> {
pub(crate) store_owner: ExpressionStoreOwnerId,
pub(crate) generic_def: GenericDefId,
pub(crate) store: &'body ExpressionStore,
pub(crate) lowering_mode: LoweringMode,
/// Generally you should not resolve things via this resolver. Instead create a TyLoweringContext
/// and resolve the path via its methods. This will ensure proper error reporting.
pub(crate) resolver: Resolver<'db>,
Expand Down Expand Up @@ -1335,6 +1340,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
store: &'body ExpressionStore,
resolver: Resolver<'db>,
allow_using_generic_params: bool,
lowering_mode: LoweringMode,
) -> Self {
let trait_env = db.trait_environment(generic_def);
let table = unify::InferenceTable::new(db, trait_env, resolver.krate(), store_owner);
Expand Down Expand Up @@ -1369,6 +1375,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
vars_emitted_type_must_be_known_for: FxHashSet::default(),
deferred_call_resolutions: FxHashMap::default(),
defined_anon_consts: RefCell::new(ThinVec::new()),
lowering_mode,
}
}

Expand Down Expand Up @@ -1969,6 +1976,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
expected_ty,
&|| self.generics(),
Some(&mut |span| self.table.next_const_var(span)),
self.lowering_mode,
(!(allow_using_generic_params && self.allow_using_generic_params)).then_some(0),
);

Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ pub use infer::{
};
pub use lower::{
FieldType, GenericDefaults, GenericDefaultsRef, GenericPredicates, ImplTraits,
LifetimeElisionKind, TyDefId, TyLoweringContext, TyLoweringInferVarsCtx, TyLoweringResult,
ValueTyDefId, diagnostics::*,
LifetimeElisionKind, LoweringMode, TyDefId, TyLoweringContext, TyLoweringInferVarsCtx,
TyLoweringResult, ValueTyDefId, diagnostics::*,
};
pub use next_solver::interner::{attach_db, attach_db_allow_change, with_attached_db};
pub use target_feature::TargetFeatures;
Expand Down
35 changes: 35 additions & 0 deletions crates/hir-ty/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,33 @@ pub trait TyLoweringInferVarsCtx<'db> {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LoweringMode {
Analysis,
Ide,
}

pub(crate) use self::tracked_struct_token::TrackedStructToken;
mod tracked_struct_token {
use super::LoweringMode;

/// A token that is required to construct tracked structs.
/// This exists to prevent one from accidentally creating a tracked struct outside of a query which may happen for some codepaths.
pub(crate) struct TrackedStructToken {
// #[non_exhaustive] doesn't work for us here, we want it module focused.
_private: (),
}

impl LoweringMode {
pub(crate) fn allow_tracked_structs(self) -> Option<TrackedStructToken> {
match self {
LoweringMode::Analysis => Some(TrackedStructToken { _private: () }),
LoweringMode::Ide => None,
}
}
}
}

pub struct TyLoweringContext<'db, 'a> {
pub db: &'db dyn HirDatabase,
pub(crate) interner: DbInterner<'db>,
Expand All @@ -211,6 +238,7 @@ pub struct TyLoweringContext<'db, 'a> {
generics: &'a OnceCell<Generics<'db>>,
in_binders: DebruijnIndex,
impl_trait_mode: ImplTraitLoweringState,
interning_mode: LoweringMode,
/// Tracks types with explicit `?Sized` bounds.
pub(crate) unsized_types: FxHashSet<Ty<'db>>,
pub(crate) diagnostics: ThinVec<TyLoweringDiagnostic>,
Expand Down Expand Up @@ -247,6 +275,7 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
store,
in_binders,
impl_trait_mode,
interning_mode: LoweringMode::Analysis,
unsized_types: FxHashSet::default(),
diagnostics: ThinVec::new(),
lifetime_elision,
Expand All @@ -261,6 +290,11 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
self.lifetime_elision = lifetime_elision;
}

pub(crate) fn with_interning_mode(mut self, interning_mode: LoweringMode) -> Self {
self.interning_mode = interning_mode;
self
}

pub(crate) fn with_debruijn<T>(
&mut self,
debruijn: DebruijnIndex,
Expand Down Expand Up @@ -390,6 +424,7 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
const_type,
&|| self.generics.get_or_init(|| generics(self.db, self.generic_def)),
create_var,
self.interning_mode,
self.forbid_params_after,
);

Expand Down
Loading