Skip to content

Commit

Permalink
Small changes to illustrate problems with the code.
Browse files Browse the repository at this point in the history
- Feel free to remove this commit from the PR when fixing the problems.
  • Loading branch information
pdamme committed Jul 23, 2024
1 parent 352964b commit 79ac932
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/runtime/local/context/DaphneContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ struct DaphneContext {

if(!stringRefCount.empty()) {
// This should not happen
std::cerr << "Deleting " << stringRefCount.size() << " remaining string refs in ~DaphneContext()" << std::endl;
logger->debug("Deleting {} remaining string refs in ~DaphneContext()", stringRefCount.size());
for (auto &ref: stringRefCount) {
delete[] reinterpret_cast<char *>(ref.first);
}
// for (auto &ref: stringRefCount) {
// delete[] reinterpret_cast<char *>(ref.first);
// }
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/runtime/local/kernels/DecRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ struct DecRef<char> {
static void apply(const char* arg, DCTX(ctx)) {
auto ptr = reinterpret_cast<uintptr_t>(arg);
if(auto found = ctx->stringRefCount.find(ptr); found != ctx->stringRefCount.end()) {
std::cerr << "DecRef: " << ptr << " (found)" << std::endl;
found->second--;
if(found->second == 0) {
ctx->logger->debug("DecRef deleting: {}", arg);
delete [] reinterpret_cast<char *>(found->first);
// delete [] reinterpret_cast<char *>(found->first);
ctx->stringRefCount.erase(found);
}
}
else {
std::cerr << "DecRef: " << ptr << " (not found)" << std::endl;
}
}
};

Expand Down
4 changes: 4 additions & 0 deletions src/runtime/local/kernels/IncRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ struct IncRef<char> {
static void apply(const char* arg, DCTX(ctx)) {
auto ptr = reinterpret_cast<uintptr_t>(arg);
if(auto found = ctx->stringRefCount.find(ptr); found != ctx->stringRefCount.end()) {
std::cerr << "IncRef: " << ptr << " (found)" << std::endl;
ctx->logger->info("IncRef: {}", arg);
found->second++;
}
else {
std::cerr << "IncRef: " << ptr << " (not found)" << std::endl;
}
}
};

Expand Down
9 changes: 9 additions & 0 deletions test/api/cli/controlflow/strings_1.daphne
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Get a string from a string literal, pass it to a function, and get back a modified string.

def foo(s:str) -> str {
return s + 123;
}

s = "abc"; # string literal, no kernel call
s = foo(s);
print(s);
1 change: 1 addition & 0 deletions test/api/cli/controlflow/strings_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abc123
9 changes: 9 additions & 0 deletions test/api/cli/controlflow/strings_2.daphne
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Get a string from a kernel, pass it to a function, and get back a modified string.

def foo(s:str) -> str {
return s + " is my favorite number";
}

s = as.str(123); # kernel call (but could be constant folded in the future)
s = foo(s);
print(s);
1 change: 1 addition & 0 deletions test/api/cli/controlflow/strings_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
123 is my favorite number

0 comments on commit 79ac932

Please sign in to comment.