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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions crates/bindings/src/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,9 @@ where
register_describer(|module| {
let params = A::schema::<I>(&mut module.inner);
let return_type = I::return_type(&mut module.inner).unwrap();
module.inner.add_view(I::NAME, true, false, params, return_type);
module
.inner
.add_view(I::NAME, module.views.len(), true, false, params, return_type);
module.views.push(I::INVOKE);
})
}
Expand All @@ -750,7 +752,9 @@ where
register_describer(|module| {
let params = A::schema::<I>(&mut module.inner);
let return_type = I::return_type(&mut module.inner).unwrap();
module.inner.add_view(I::NAME, true, true, params, return_type);
module
.inner
.add_view(I::NAME, module.views_anon.len(), true, true, params, return_type);
module.views_anon.push(I::INVOKE);
})
}
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/db/relational_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,7 @@ pub mod tests_utils {

builder.add_view(
name,
0,
true,
is_anonymous,
ProductType::unit(),
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/host/wasm_common/module_host_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,11 +791,11 @@ impl InstanceCommon {
return_type,
timestamp,
view_db_id,
..
is_anonymous,
} = params;

let info = self.info.clone();
let view_def = info.module_def.view_by_id(view_id);
let view_def = info.module_def.view_by_id(view_id, is_anonymous);
let view_name = &*view_def.name;

let _outer_span = start_call_function_span(view_name, &caller_identity, caller_connection_id);
Expand Down
2 changes: 1 addition & 1 deletion crates/expr/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ mod tests {
let product_type = AlgebraicType::from(columns.into());
let type_ref = builder.add_algebraic_type([], name, product_type, true);
let return_type = AlgebraicType::array(AlgebraicType::Ref(type_ref));
builder.add_view(name, true, is_anonymous, ProductType::unit(), return_type);
builder.add_view(name, 0, true, is_anonymous, ProductType::unit(), return_type);
}

let mut builder = RawModuleDefV9Builder::new();
Expand Down
5 changes: 5 additions & 0 deletions crates/lib/src/db/raw_def/v9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ pub struct RawViewDefV9 {
/// The name of the view function as defined in the module
pub name: RawIdentifier,

/// The index of the view in the module's list of views.
pub index: u32,

/// Is this a public or a private view?
/// Currently only public views are supported.
/// Private views may be supported in the future.
Expand Down Expand Up @@ -732,13 +735,15 @@ impl RawModuleDefV9Builder {
pub fn add_view(
&mut self,
name: impl Into<RawIdentifier>,
index: usize,
is_public: bool,
is_anonymous: bool,
params: ProductType,
return_type: AlgebraicType,
) {
self.module.misc_exports.push(RawMiscModuleExportV9::View(RawViewDefV9 {
name: name.into(),
index: index as u32,
is_public,
is_anonymous,
params,
Expand Down
26 changes: 26 additions & 0 deletions crates/schema/src/auto_migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,7 @@ mod tests {
let view_return_ty_ref = builder.add_algebraic_type([], "my_view_return", view_return_ty, true);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32), ("y", AlgebraicType::U32)]),
Expand Down Expand Up @@ -1206,6 +1207,7 @@ mod tests {
let view_return_ty_ref = builder.add_algebraic_type([], "my_view_return", view_return_ty, true);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand Down Expand Up @@ -1765,6 +1767,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand Down Expand Up @@ -1793,6 +1796,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand Down Expand Up @@ -1835,6 +1839,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand All @@ -1850,6 +1855,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand All @@ -1868,6 +1874,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand All @@ -1883,6 +1890,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand Down Expand Up @@ -1937,6 +1945,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand All @@ -1952,6 +1961,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
false,
ProductType::from([("x", AlgebraicType::U32)]),
Expand All @@ -1970,6 +1980,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand All @@ -1985,6 +1996,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32), ("y", AlgebraicType::U32)]),
Expand All @@ -2003,6 +2015,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32), ("y", AlgebraicType::U32)]),
Expand All @@ -2018,6 +2031,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand All @@ -2036,6 +2050,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32), ("y", AlgebraicType::U32)]),
Expand All @@ -2051,6 +2066,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("y", AlgebraicType::U32), ("x", AlgebraicType::U32)]),
Expand All @@ -2069,6 +2085,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand All @@ -2084,6 +2101,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand All @@ -2102,6 +2120,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand All @@ -2117,6 +2136,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand All @@ -2135,6 +2155,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand All @@ -2150,6 +2171,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand All @@ -2168,6 +2190,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand All @@ -2183,6 +2206,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand All @@ -2201,6 +2225,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand All @@ -2216,6 +2241,7 @@ mod tests {
);
builder.add_view(
"my_view",
0,
true,
true,
ProductType::from([("x", AlgebraicType::U32)]),
Expand Down
17 changes: 14 additions & 3 deletions crates/schema/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl ModuleDef {
/// Convenience method to look up a view, possibly by a string, returning its id as well.
pub fn view_full<K: ?Sized + Hash + Equivalent<Identifier>>(&self, name: &K) -> Option<(ViewId, &ViewDef)> {
// If the string IS a valid identifier, we can just look it up.
self.views.get_full(name).map(|(idx, _, def)| (idx.into(), def))
self.views.get(name).map(|def| (def.index, def))
}

/// Convenience method to look up a reducer, possibly by a string.
Expand Down Expand Up @@ -296,8 +296,12 @@ impl ModuleDef {
}

/// Look up a view by its id, panicking if it doesn't exist.
pub fn view_by_id(&self, id: ViewId) -> &ViewDef {
&self.views[id.idx()]
pub fn view_by_id(&self, id: ViewId, is_anonymoys: bool) -> &ViewDef {
self.views
.iter()
.find(|(_, def)| def.index == id && def.is_anonymous == is_anonymoys)
.expect("view id not found")
.1
}

/// Looks up a lifecycle reducer defined in the module.
Expand Down Expand Up @@ -1111,6 +1115,11 @@ pub struct ViewDef {
/// This type does not have access to the `Identity` of the caller.
pub is_anonymous: bool,

/// It represents the unique index of this view within the module.
/// Module contains separate list for anonymous and non-anonymous views,
/// so `is_anonymous` is needed to fully identify the view along with this index.
pub index: ViewId,

/// The parameters of the view.
///
/// This `ProductType` need not be registered in the module's `Typespace`.
Expand Down Expand Up @@ -1171,10 +1180,12 @@ impl From<ViewDef> for RawViewDefV9 {
is_public,
params,
return_type,
index,
..
} = val;
RawViewDefV9 {
name: name.into(),
index: index.into(),
is_anonymous,
is_public,
params,
Expand Down
2 changes: 2 additions & 0 deletions crates/schema/src/def/validate/v9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ impl ModuleValidator<'_> {
is_anonymous,
params,
return_type,
index,
} = view_def;

let invalid_return_type = || {
Expand Down Expand Up @@ -541,6 +542,7 @@ impl ModuleValidator<'_> {
is_anonymous,
is_public,
params,
index: index.into(),
params_for_generate: ProductTypeDef {
elements: params_for_generate,
recursive: false, // A `ProductTypeDef` not stored in a `Typespace` cannot be recursive.
Expand Down
Loading