From f1b4d535c608ba865b1a28faf6aae9392b3824b3 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 11 Dec 2020 20:46:46 +0100 Subject: [PATCH] add other effect functions --- compiler/mono/src/ir.rs | 31 ++++++++++++++++--- examples/effect/Main.roc | 5 ++- .../effect/thing/platform-dir/Pkg-Config.roc | 15 +++------ examples/effect/thing/platform-dir/Task.roc | 5 ++- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 52751e54f6..df65db2c39 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -4749,10 +4749,33 @@ fn reuse_function_symbol<'a>( ) -> Stmt<'a> { match procs.partial_procs.get(&original) { None => { - // danger: a foreign symbol may not be specialized! - debug_assert!( - env.home == original.module_id() || original.module_id() == ModuleId::ATTR - ); + let is_imported = + !(env.home == original.module_id() || original.module_id() == ModuleId::ATTR); + + match arg_var { + Some(arg_var) if is_imported => { + let layout = layout_cache + .from_var(env.arena, arg_var, env.subs) + .expect("creating layout does not fail"); + + procs.insert_passed_by_name( + env, + arg_var, + original, + layout.clone(), + layout_cache, + ); + } + _ => { + // danger: a foreign symbol may not be specialized! + debug_assert!( + !is_imported, + "symbol {:?} while processing module {:?}", + original, + (env.home, &arg_var), + ); + } + } result } diff --git a/examples/effect/Main.roc b/examples/effect/Main.roc index ac6fd59921..3edf50224d 100644 --- a/examples/effect/Main.roc +++ b/examples/effect/Main.roc @@ -4,6 +4,5 @@ app "effect-example" provides [ main ] to base main : Task.Task {} F64 -main = - # Task.after (Task.always "foo") (\_ -> Task.always {}) - Task.after (Task.putLine "foo") \{} -> Task.putLine "bar" +main = + Task.after (Task.getLine {}) \lineThisThing -> Task.putLine lineThisThing diff --git a/examples/effect/thing/platform-dir/Pkg-Config.roc b/examples/effect/thing/platform-dir/Pkg-Config.roc index ea568307ff..9d6ea3da92 100644 --- a/examples/effect/thing/platform-dir/Pkg-Config.roc +++ b/examples/effect/thing/platform-dir/Pkg-Config.roc @@ -2,20 +2,15 @@ platform folkertdev/foo requires { main : Effect {} } exposes [] packages {} - imports [] + imports [Task] provides [ mainForHost ] effects Effect { - putLine : Str -> Effect {} + putChar : I64 -> Effect {}, + putLine : Str -> Effect {}, + getLine : {} -> Effect Str } -# putChar : I64 -> Effect {}, -# getLine : Effect Str - - -Effect a : [ Effect ({} -> a) ] -Task a err : Effect (Result a err) - -mainForHost : Task {} F64 as Fx +mainForHost : Task.Task {} F64 as Fx mainForHost = main diff --git a/examples/effect/thing/platform-dir/Task.roc b/examples/effect/thing/platform-dir/Task.roc index 72af3c8f06..b49cdfc3c0 100644 --- a/examples/effect/thing/platform-dir/Task.roc +++ b/examples/effect/thing/platform-dir/Task.roc @@ -1,5 +1,5 @@ interface Task - exposes [ Task, after, always, fail, putLine, map ] + exposes [ Task, after, always, fail, map, putLine, getLine ] imports [ Effect ] Task a err : Effect.Effect (Result a err) @@ -10,6 +10,9 @@ always = \x -> Effect.always (Ok x) fail : err -> Task * err fail = \x -> Effect.always (Err x) +getLine : {} -> Task Str * +getLine = \{} -> Effect.after (Effect.getLine {}) always + putLine : Str -> Task {} * putLine = \line -> Effect.map (Effect.putLine line) (\_ -> Ok {})