From 873926915faf2a567653fa333f34d5c852abd42e Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Tue, 15 Dec 2015 10:42:21 -0800 Subject: [PATCH] Don't allow fibers as map keys. I hacked in support for it for a misguided reason (trying to fake "thread-local storage") and ended up not using it for that anyway. --- src/vm/wren_primitive.c | 4 ++-- src/vm/wren_value.c | 4 ---- src/vm/wren_value.h | 4 ---- src/vm/wren_vm.h | 5 ----- test/core/map/contains_key_not_value.wren | 2 +- test/core/map/key_types.wren | 8 +++----- test/core/map/remove_key_not_value.wren | 2 +- test/core/map/subscript_key_not_value.wren | 2 +- test/core/map/subscript_setter_key_not_value.wren | 2 +- 9 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/vm/wren_primitive.c b/src/vm/wren_primitive.c index 5c729637..c932a2dd 100644 --- a/src/vm/wren_primitive.c +++ b/src/vm/wren_primitive.c @@ -54,13 +54,13 @@ bool validateInt(WrenVM* vm, Value arg, const char* argName) bool validateKey(WrenVM* vm, Value arg) { - if (IS_BOOL(arg) || IS_CLASS(arg) || IS_FIBER(arg) || IS_NULL(arg) || + if (IS_BOOL(arg) || IS_CLASS(arg) || IS_NULL(arg) || IS_NUM(arg) || IS_RANGE(arg) || IS_STRING(arg)) { return true; } - vm->fiber->error = CONST_STRING(vm, "Key must be a value type or fiber."); + vm->fiber->error = CONST_STRING(vm, "Key must be a value type."); return false; } diff --git a/src/vm/wren_value.c b/src/vm/wren_value.c index 586999e1..c0970762 100644 --- a/src/vm/wren_value.c +++ b/src/vm/wren_value.c @@ -155,7 +155,6 @@ ObjFiber* wrenNewFiber(WrenVM* vm, Obj* fn) ObjFiber* fiber = ALLOCATE(vm, ObjFiber); initObj(vm, &fiber->obj, OBJ_FIBER, vm->fiberClass); - fiber->id = vm->nextFiberId++; fiber->frames = frames; fiber->frameCapacity = INITIAL_CALL_FRAMES; fiber->stack = stack; @@ -344,9 +343,6 @@ static uint32_t hashObject(Obj* object) // Classes just use their name. return hashObject((Obj*)((ObjClass*)object)->name); - case OBJ_FIBER: - return ((ObjFiber*)object)->id; - case OBJ_RANGE: { ObjRange* range = (ObjRange*)object; diff --git a/src/vm/wren_value.h b/src/vm/wren_value.h index 81485c18..702538ff 100644 --- a/src/vm/wren_value.h +++ b/src/vm/wren_value.h @@ -242,10 +242,6 @@ typedef struct sObjFiber // error object. Otherwise, it will be null. Value error; - // A unique-ish numeric ID for the fiber. Lets fibers be used as map keys. - // Unique-ish since IDs may overflow and wrap around. - uint16_t id; - // This will be true if the caller that called this fiber did so using "try". // In that case, if this fiber fails with an error, the error will be given // to the caller. diff --git a/src/vm/wren_vm.h b/src/vm/wren_vm.h index ed6a810d..fd7090e2 100644 --- a/src/vm/wren_vm.h +++ b/src/vm/wren_vm.h @@ -50,11 +50,6 @@ struct WrenVM // for the module. ObjMap* modules; - // The ID that will be assigned to the next fiber that is allocated. Fibers - // are given unique-ish (not completely unique since this can overflow) IDs - // so that they can be used as map keys. - uint16_t nextFiberId; - // Memory management data: // The number of bytes that are known to be currently allocated. Includes all diff --git a/test/core/map/contains_key_not_value.wren b/test/core/map/contains_key_not_value.wren index 90c8363f..0477be74 100644 --- a/test/core/map/contains_key_not_value.wren +++ b/test/core/map/contains_key_not_value.wren @@ -1 +1 @@ -var result = {}.containsKey([]) // expect runtime error: Key must be a value type or fiber. +var result = {}.containsKey([]) // expect runtime error: Key must be a value type. diff --git a/test/core/map/key_types.wren b/test/core/map/key_types.wren index e6ec71dc..73360e69 100644 --- a/test/core/map/key_types.wren +++ b/test/core/map/key_types.wren @@ -8,8 +8,7 @@ var map = { 1.2: "1 point 2", List: "list class", "null": "string value", - (1..3): "1 to 3", - fiber: "fiber" + (1..3): "1 to 3" } System.print(map[null]) // expect: null value @@ -20,9 +19,8 @@ System.print(map[1.2]) // expect: 1 point 2 System.print(map[List]) // expect: list class System.print(map["null"]) // expect: string value System.print(map[1..3]) // expect: 1 to 3 -System.print(map[fiber]) // expect: fiber -System.print(map.count) // expect: 9 +System.print(map.count) // expect: 8 // Use the same keys (but sometimes different objects) to ensure keys have the // right equality semantics. @@ -44,4 +42,4 @@ System.print(map[List]) // expect: new list class System.print(map["null"]) // expect: new string value System.print(map[1..3]) // expect: new 1 to 3 -System.print(map.count) // expect: 9 +System.print(map.count) // expect: 8 diff --git a/test/core/map/remove_key_not_value.wren b/test/core/map/remove_key_not_value.wren index 8252d543..6ebab4dc 100644 --- a/test/core/map/remove_key_not_value.wren +++ b/test/core/map/remove_key_not_value.wren @@ -1 +1 @@ -var result = {}.remove([]) // expect runtime error: Key must be a value type or fiber. +var result = {}.remove([]) // expect runtime error: Key must be a value type. diff --git a/test/core/map/subscript_key_not_value.wren b/test/core/map/subscript_key_not_value.wren index f68980c1..8e813e01 100644 --- a/test/core/map/subscript_key_not_value.wren +++ b/test/core/map/subscript_key_not_value.wren @@ -1 +1 @@ -var result = {}[[]] // expect runtime error: Key must be a value type or fiber. +var result = {}[[]] // expect runtime error: Key must be a value type. diff --git a/test/core/map/subscript_setter_key_not_value.wren b/test/core/map/subscript_setter_key_not_value.wren index 158b8f58..c8ec79b1 100644 --- a/test/core/map/subscript_setter_key_not_value.wren +++ b/test/core/map/subscript_setter_key_not_value.wren @@ -1 +1 @@ -var result = {}[[]] = "value" // expect runtime error: Key must be a value type or fiber. +var result = {}[[]] = "value" // expect runtime error: Key must be a value type.