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
2 changes: 1 addition & 1 deletion rib-lang/src/compiler/byte_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Display for RibByteCodeGenerationError {
write!(f, "Unresolved wasm component for function: {function}")
}
RibByteCodeGenerationError::UnresolvedWorkerName => {
write!(f, "inline invocation of functions on a worker instance is currently not supported")
write!(f, "inline invocation of functions on an instance expression is currently not supported")
}
_ => {
write!(f, "inline invocation of methods on resource constructor instance is currently not supported")
Expand Down
2 changes: 1 addition & 1 deletion rib-lang/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub struct DefaultWorkerNameGenerator;
impl GenerateWorkerName for DefaultWorkerNameGenerator {
fn generate_worker_name(&self) -> String {
let uuid = uuid::Uuid::new_v4();
format!("worker-{uuid}")
format!("instance-{uuid}")
}
}

Expand Down
10 changes: 5 additions & 5 deletions rib-lang/src/instance_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ use std::ops::Deref;
// the type of instance becomes more and more precise.
//
// Please look at `InstanceCreationType`
// for a tangible view on the fact that an instance can be either worker or a resource.
// for a tangible view on the fact that an instance can be either a component instance or a resource.
#[derive(Debug, Hash, Clone, Eq, PartialEq, PartialOrd, Ord)]
pub enum InstanceType {
// Worker instance: one component's exports (all packages/interfaces merged in the dictionary)
// Component instance: one component's exports (all packages/interfaces merged in the dictionary)
Global {
worker_name: Option<Box<Expr>>,
/// Shared across all worker-instance types for one compile — avoids cloning [`FunctionDictionary`] per node.
/// Shared across all instance types for one compile — avoids cloning [`FunctionDictionary`] per node.
component: Arc<ComponentDependency>,
},

Expand Down Expand Up @@ -292,7 +292,7 @@ fn search_function_in_single_package(
interfaces.sort();

Err(format!(
"multiple interfaces contain function '{function_name}'; disambiguate with a fully qualified WIT call (e.g. ns:pkg/interface.{{fn}}). interfaces: {}",
"multiple interfaces contain function '{function_name}'. Rib does not currently support disambiguating instance method names across interfaces. interfaces: {}",
interfaces.join(", ")
))
}
Expand All @@ -303,7 +303,7 @@ fn search_function_in_multiple_packages(
package_map: HashMap<Option<PackageName>, HashSet<Option<InterfaceName>>>,
) -> Result<Function, String> {
let mut error_msg = format!(
"function '{function_name}' exists in multiple packages; use a fully qualified WIT call site to disambiguate: "
"function '{function_name}' exists in multiple packages. Rib does not currently support disambiguating instance method names in this case. Conflicting exports: "
);

let mut package_interface_list = package_map
Expand Down
24 changes: 12 additions & 12 deletions rib-lang/src/interpreter/rib_interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ mod internal {
Some(worker_id) => {
let value_and_type = worker_id.get_val().ok_or_else(|| {
internal_corrupted_state!(
"expected a worker name to be present in the environment, but it was not found"
"expected an instance name to be present in the environment, but it was not found"
)
})?;

Expand Down Expand Up @@ -1212,15 +1212,15 @@ mod internal {
.map(|x| {
x.get_val().ok_or_else(|| {
internal_corrupted_state!(
"failed to get a worker variable id for function {}",
"failed to get an instance variable id for function {}",
function_name
)
})
})
.transpose()?
.ok_or_else(|| {
internal_corrupted_state!(
"failed to find a worker with id {}",
"failed to find an instance with id {}",
variable_id.name()
)
})?;
Expand All @@ -1230,7 +1230,7 @@ mod internal {
.get_literal()
.map(|v| v.as_string())
.ok_or_else(|| {
internal_corrupted_state!("failed to get a worker name for variable")
internal_corrupted_state!("failed to get an instance name for variable")
})?;

let result = interpreter_env
Expand Down Expand Up @@ -3328,7 +3328,7 @@ mod tests {

assert_eq!(
error.to_string(),
"inline invocation of functions on a worker instance is currently not supported"
"inline invocation of functions on an instance expression is currently not supported"
);
}

Expand All @@ -3349,7 +3349,7 @@ mod tests {

let compiled = compiler.compile(expr).unwrap_err().to_string();

assert_eq!(compiled, "error in the following rib found at line 2, column 28\n`instance`\ncause: `instance` is a reserved keyword\nhelp: use `instance()` instead of `instance` to create an ephemeral worker instance.\nhelp: for a durable worker, use `instance(\"foo\")` where `\"foo\"` is the worker name\n".to_string());
assert_eq!(compiled, "error in the following rib found at line 2, column 28\n`instance`\ncause: `instance` is a reserved keyword\nhelp: use `instance()` instead of `instance` to create an ephemeral instance.\nhelp: for a named instance, use `instance(\"foo\")` where `\"foo\"` is the instance name\n".to_string());
}

#[test]
Expand All @@ -3372,7 +3372,7 @@ mod tests {

assert_eq!(
compilation_error,
"error in the following rib found at line 3, column 30\n`x.bar(\"bar\")`\ncause: invalid function call `bar`\nmultiple interfaces contain function 'bar'; disambiguate with a fully qualified WIT call (e.g. ns:pkg/interface.{fn}). interfaces: api1, api2\n".to_string()
"error in the following rib found at line 3, column 30\n`x.bar(\"bar\")`\ncause: invalid function call `bar`\nmultiple interfaces contain function 'bar'. Rib does not currently support disambiguating instance method names across interfaces. interfaces: api1, api2\n".to_string()
);
}

Expand Down Expand Up @@ -3494,7 +3494,7 @@ mod tests {

assert_eq!(
compilation_error,
"error in the following rib found at line 3, column 30\n`worker.bar(\"bar\")`\ncause: invalid function call `bar`\nmultiple interfaces contain function 'bar'; disambiguate with a fully qualified WIT call (e.g. ns:pkg/interface.{fn}). interfaces: api1, api2\n".to_string()
"error in the following rib found at line 3, column 30\n`worker.bar(\"bar\")`\ncause: invalid function call `bar`\nmultiple interfaces contain function 'bar'. Rib does not currently support disambiguating instance method names across interfaces. interfaces: api1, api2\n".to_string()
);
}

Expand Down Expand Up @@ -3542,7 +3542,7 @@ mod tests {

assert_eq!(
compiled,
"error in the following rib found at line 3, column 30\n`worker.qux(\"bar\")`\ncause: invalid function call `qux`\nfunction 'qux' exists in multiple packages; use a fully qualified WIT call site to disambiguate: amazon:shopping-cart (interfaces: api1), wasi:clocks (interfaces: monotonic-clock)\n".to_string()
"error in the following rib found at line 3, column 30\n`worker.qux(\"bar\")`\ncause: invalid function call `qux`\nfunction 'qux' exists in multiple packages. Rib does not currently support disambiguating instance method names in this case. Conflicting exports: amazon:shopping-cart (interfaces: api1), wasi:clocks (interfaces: monotonic-clock)\n".to_string()
);
}

Expand Down Expand Up @@ -4758,8 +4758,8 @@ mod tests {
}
}

// The interpreter that always returns a record value consisting of function name, worker name etc
// for every function calls in Rib, so tests can assert the invoke target (worker name, function, args).
// The interpreter that always returns a record value consisting of function name, instance name, etc.
// for every function calls in Rib, so tests can assert the invoke target (instance name, function, args).
pub(crate) fn interpreter_with_resource_function_invoke_impl(
rib_input: Option<RibInput>,
) -> Interpreter {
Expand Down Expand Up @@ -5165,7 +5165,7 @@ mod tests {
}

// A pass through function simply pass through the information embedded in a function call
// such as function name, the worker name and the arguments used to invoke the call
// such as function name, the instance name and the arguments used to invoke the call
// allowing us to cross verify if the invoke is correct
pub(crate) fn test_deps_for_pass_through_function() -> RibTestDeps {
let exports = vec![WitExport::Function(WitFunction {
Expand Down
6 changes: 3 additions & 3 deletions rib-lang/src/type_checker/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ fn try_invalid_function_calls_for_node(
FunctionCallError::InvalidFunctionCall {
function_name: function_name.function.name_pretty().to_string(),
source_span: node.source_span.clone(),
message: "function call is not associated with a wasm component. make sure component functions are called after creating an instance using `instance(<optional-worker-name>)`".to_string(),
message: "function call is not associated with a wasm component. make sure component functions are called after creating an instance using `instance(<optional-name>)`".to_string(),
}
.into(),
);
Expand Down Expand Up @@ -324,8 +324,8 @@ fn call_type_node_additional_detail(ct: &CallTypeNode) -> String {
CallTypeNode::InstanceCreation(ic) => match ic {
InstanceCreationNode::WitWorker { worker_name, .. } => {
let wn = worker_name
.map(|_| "(worker expr)")
.map_or(String::new(), |s| format!(", with worker `{s}`"));
.map(|_| "(instance name expr)")
.map_or(String::new(), |s| format!(", with instance name `{s}`"));
format!("cannot determine the type of instance creation `{wn}`")
}
InstanceCreationNode::WitResource {
Expand Down
4 changes: 2 additions & 2 deletions rib-lang/src/type_inference/identify_instance_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ fn search_for_invalid_instance_declarations_arena(
if variable_id.name() == "instance" && variable_id.is_global() {
return Err(CustomError::new(span, "`instance` is a reserved keyword")
.with_help_message(
"use `instance()` instead of `instance` to create an ephemeral worker instance.",
"use `instance()` instead of `instance` to create an ephemeral instance.",
)
.with_help_message(
"for a durable worker, use `instance(\"foo\")` where `\"foo\"` is the worker name",
"for a named instance, use `instance(\"foo\")` where `\"foo\"` is the instance name",
)
.into());
}
Expand Down
2 changes: 1 addition & 1 deletion rib-lang/src/type_inference/type_pull_up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ fn handle_residual_method_invokes_arena(
source_span: source_span.clone(),
help_message: vec![],
message: format!(
"invalid method invocation `{lhs_name}.{method}`. make sure `{lhs_name}` is defined and is a valid instance type (i.e, resource or worker)"
"invalid method invocation `{lhs_name}.{method}`. make sure `{lhs_name}` is defined and is a valid instance type (including resources)"
),
}
.into())
Expand Down
2 changes: 1 addition & 1 deletion rib-lang/src/type_inference/worker_function_invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ pub fn infer_function_invokes(
FunctionCallError::invalid_function_call(
&method,
span.clone(),
"invalid worker function invoke. Expected to be an instance type",
"invalid instance method invoke. expected lhs to be an instance type",
),
));
}
Expand Down
4 changes: 2 additions & 2 deletions rib-repl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Example: Once the component is loaded, the following will result in `3`, if the

```
>>> let a = instance();
>>> let b = a.increment_and_get();
>>> let c = a.increment_and_get();
>>> let b = a.increment-and-get();
>>> let c = a.increment-and-get();
>>> b + c
```

Expand Down
8 changes: 4 additions & 4 deletions rib-repl/src/instance_name_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::sync::Arc;

// When it comes to REPL, unlike the regular Rib execution,
// it recompiles from the start anytime to figure out the types
// however it shouldn't result in a variable having a different instance of worker,
// meaning different worker name. Rib internally generates a worker name at compile time
// for instances without worker-name, i.e, `instance()` compared to `instance("my-worker")`.
// however it shouldn't result in a variable having a different logical instance,
// meaning a different generated instance name. Rib internally generates an instance name at compile time
// for `instance()` compared to `instance("my-worker")`.
pub struct ReplInstanceNameGen {
pub instance_count: u64,
pub worker_name_cache: HashMap<u64, String>,
Expand Down Expand Up @@ -35,7 +35,7 @@ impl ReplInstanceNameGen {
return name.clone();
}
let uuid = uuid::Uuid::new_v4();
let name = format!("worker-{}-{}", self.instance_count, uuid);
let name = format!("instance-{}-{}", self.instance_count, uuid);
self.worker_name_cache
.insert(self.instance_count, name.clone());
name
Expand Down
2 changes: 1 addition & 1 deletion rib-repl/src/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub trait ComponentFunctionInvoke {

// Note: Currently, the Rib interpreter supports only one component, so the
// `RibFunctionInvoke` trait in the `golem-rib` module does not include `component_id` in
// the `invoke` arguments. It only requires the optional worker name, function name, and arguments.
// the `invoke` arguments. It only requires the optional instance name, function name, and arguments.
// Once multi-component support is added, the trait will be updated to include `component_id`,
// and we can use it directly instead of `WorkerFunctionInvoke` in the `golem-rib-repl` module.
pub(crate) struct ReplRibFunctionInvoke {
Expand Down
4 changes: 2 additions & 2 deletions rib-repl/src/repl_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ impl ReplState {
}

// This reset is to ensure the rib compiler the REPL can reuse the previous
// compilations (within the same session) worker names generated. i.e, before every compilation we reset the instance count,
// and there by, for the new script, the instance creation will end up reusing already generated worker names.
// compilations (within the same session) instance names generated. i.e, before every compilation we reset the instance count,
// and thereby, for the new script, the instance creation will end up reusing already generated instance names.
pub fn reset_instance_count(&self) {
self.worker_name_gen.write().unwrap().reset_instance_count();
}
Expand Down
Loading