Skip to content

Commit

Permalink
Convert MethodLibrary's SkylarkSignature methods to SkylarkCallable
Browse files Browse the repository at this point in the history
Note that converted parameter @param annotations need legacyNamed = true (and in some places, noneable = True) to retain compatibility with the bugginess of SkylarkSignature.

This facilitates followup to clean up these methods / parameters -- given the refactor, we can enforce some of these parameters are positional-only (subject to an --incompatible flag)

Progress toward bazelbuild#5010

RELNOTES: None.
PiperOrigin-RevId: 230975480
  • Loading branch information
c-parsons authored and Copybara-Service committed Jan 25, 2019
1 parent 6b96ff7 commit d3dd9d1
Show file tree
Hide file tree
Showing 16 changed files with 517 additions and 594 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/google/devtools/build/docgen/ApiExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkInterfaceUtils;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.syntax.BaseFunction;
import com.google.devtools.build.lib.syntax.BuiltinCallable;
import com.google.devtools.build.lib.syntax.FuncallExpression;
import com.google.devtools.build.lib.syntax.FunctionSignature;
import com.google.devtools.build.lib.syntax.MethodDescriptor;
Expand Down Expand Up @@ -93,6 +94,15 @@ private static void appendGlobals(Builtins.Builder builtins, Map<String, Object>
Value.Builder value = Value.newBuilder();
if (obj instanceof BaseFunction) {
value = collectFunctionInfo((BaseFunction) obj);
} else if (obj instanceof BuiltinCallable) {
BuiltinCallable builtinCallable = (BuiltinCallable) obj;
MethodDescriptor descriptor =
builtinCallable.getMethodDescriptor(SkylarkSemantics.DEFAULT_SEMANTICS);
value =
collectFunctionInfo(
descriptor.getName(),
SkylarkSignatureProcessor.getSignatureForCallable(
descriptor.getName(), descriptor, null, null));
} else {
value.setName(entry.getKey());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public Object call(
FuncallExpression ast,
Environment env)
throws EvalException, InterruptedException {
MethodDescriptor methodDescriptor =
FuncallExpression.getMethod(env.getSemantics(), obj.getClass(), methodName);
MethodDescriptor methodDescriptor = getMethodDescriptor(env.getSemantics());

// TODO(cparsons): Profiling should be done at the MethodDescriptor level.
try (SilentCloseable c =
Expand All @@ -55,6 +54,10 @@ public Object call(
}
}

public MethodDescriptor getMethodDescriptor(SkylarkSemantics semantics) {
return FuncallExpression.getMethod(semantics, obj.getClass(), methodName);
}

@Override
public void repr(SkylarkPrinter printer) {
printer.append("<built-in function " + methodName + ">");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ private EvalException unexpectedKeywordArgumentException(
String.format(
"unexpected keyword%s %s",
unexpectedKeywords.size() > 1 ? "s" : "",
Joiner.on(",").join(Iterables.transform(unexpectedKeywords, s -> "'" + s + "'"))),
Joiner.on(", ").join(Iterables.transform(unexpectedKeywords, s -> "'" + s + "'"))),
method,
objClass);
}
Expand Down
Loading

0 comments on commit d3dd9d1

Please sign in to comment.